PHP Date & Time format Related

Set timezone:

Today:

https://www.php.net/manual/en/function.date.php

Add 1 day:
date(‘Y-m-d G:i:s’, strtotime($fromDate) + 60*60*24) (Not recommended)
Solution:

  • note: timestamp – the number of seconds since January 1 1970 00:00:00 GMT (millisecond in javascript)
  • Get current Time: time();
  • 日期比較:
    SELECT *
    FROM form_contact_log
    WHERE created_time >= date_format( ‘2011-5-1’, ‘%Y-%m-%d’)
    Note: 一定要加單引號
  • Make time:$tomorrow = mktime(0,0,0,date(“m”),date(“d”)+1,date(“Y”));
  • Validate a date string: strtotime(string)
    If the string is not a date string, the result will be “false”
    (Javascript: new Date(‘2012-10-40’) == ‘Invalid Date’ )
  • Dispaly time only:
    date(‘g:i A’, strtotime($cell))

4 thoughts on “PHP Date & Time format Related

  1. web hosting

    “hey there, this might be little offtopic, but i am hosting my site on hostgator and they’ll suspend my hosting in 4days, so i would like to ask you which hosting do you use or suggest?”

  2. timothy

    I’m excited to uncover this great site. I wanted to thank you for ones time for this particularly wonderful read!! I definitely appreciated every little bit of it and I have you book marked to look at new stuff on your site.

Comments are closed.