Getting Date and Time Elements

Using the current DateTime
  $MyString = "This current DateTime: " . gmdate('Y-m-d H:i:s');  //gmdate() for UTC, date() gives you the servers local timezone, not UTC.
  
  $TheHourNow = intval(gmdate("H"));
Using a DateTime variable
  $ModifiedDateTime = gmdate('Y-m-d H:i:s', strtotime($MyDateTime));

  //"Y-m-d H:i:s' gives "2000-01-01 00:00:00"

  $Year = intval(gmdate('Y', strtotime($MyDateTime)));
  $Month = intval(gmdate('n', strtotime($MyDateTime)));
  $DayOfMonth = intval(gmdate('j', strtotime($MyDateTime)));
  $Hour = intval(gmdate('G', strtotime($MyDateTime)));

Parameters you can use

Calculations

Date in # days time
  $project_end_date = gmdate("Y-m-d", mktime(gmdate('H'),gmdate('i'),gmdate('s'), gmdate('m'),gmdate('d') + 30,gmdate('Y')));

Compare Date Time

     $now = strtotime(gmdate("Y-m-d H:i:s"));
     $end = strtotime($UpgradesValidUntil);
     if ($now > $end)
     {
     }


     if ( strtotime($MyDateTimeString1) > strtotime($MyDateTimeString2) )
     {
     }

MYSQL Date & Time

To set a DateTime field to now use:

Now()

(Don’t add single quotes around it)

Is String A DateTime?

  if (strtotime($CreatedDateTime) !== FALSE)    //Returns timestamp on success, false otherwise
    //Yes string is a date

//Or, assign the value:
  if ( ($CreatedDateTime = strtotime($CreatedDateTime)) === False )
  {
    //An error occured
  }

Convert DateTime

See Strings-Values