{"id":126,"date":"2011-12-24T14:48:16","date_gmt":"2011-12-24T14:48:16","guid":{"rendered":"https:\/\/ibex.tech\/cloud\/?p=126"},"modified":"2026-06-17T09:22:39","modified_gmt":"2026-06-17T08:22:39","slug":"date-and-time","status":"publish","type":"post","link":"https:\/\/ibex.tech\/cloud\/php\/date-and-time\/date-and-time","title":{"rendered":"Date And Time"},"content":{"rendered":"\n<h4 class=\"wp-block-heading\">Getting Date and Time Elements<\/h4>\n\n\n\n<h5 class=\"wp-block-heading\">Using the current DateTime<\/h5>\n\n\n\n<pre class=\"wp-block-code\"><code>  $MyString = \"This current DateTime: \" . gmdate('Y-m-d H:i:s');  \/\/gmdate() for UTC, date() gives you the servers local timezone, not UTC.\n  \n  $TheHourNow = intval(gmdate(\"H\"));\n<\/code><\/pre>\n\n\n\n<h5 class=\"wp-block-heading\">Using a DateTime variable<\/h5>\n\n\n\n<pre class=\"wp-block-code\"><code>  $ModifiedDateTime = gmdate('Y-m-d H:i:s', strtotime($MyDateTime));\n\n  \/\/\"Y-m-d H:i:s' gives \"2000-01-01 00:00:00\"\n\n  $Year = intval(gmdate('Y', strtotime($MyDateTime)));\n  $Month = intval(gmdate('n', strtotime($MyDateTime)));\n  $DayOfMonth = intval(gmdate('j', strtotime($MyDateTime)));\n  $Hour = intval(gmdate('G', strtotime($MyDateTime)));<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><a href=\"https:\/\/www.php.net\/manual\/en\/datetime.format.php\" target=\"_blank\" rel=\"noreferrer noopener\">Parameters you can use<\/a><\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Calculations<\/h4>\n\n\n\n<h5 class=\"wp-block-heading\">Date in # days time <\/h5>\n\n\n\n<pre class=\"wp-block-code\"><code>  $project_end_date = gmdate(\"Y-m-d\", mktime(gmdate('H'),gmdate('i'),gmdate('s'), gmdate('m'),gmdate('d') + 30,gmdate('Y')));<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Compare Date Time <\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>     $now = strtotime(gmdate(\"Y-m-d H:i:s\"));\n     $end = strtotime($UpgradesValidUntil);\n     if ($now > $end)\n     {\n     }\n\n\n     if ( strtotime($MyDateTimeString1) > strtotime($MyDateTimeString2) )\n     {\n     }<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">MYSQL Date &amp; Time <\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">To set a DateTime field to now use: <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Now()<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">(Don&#8217;t add single quotes around it) <\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Is String A DateTime?<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>  if (strtotime($CreatedDateTime) !== FALSE)    \/\/Returns timestamp on success, false otherwise\n    \/\/Yes string is a date\n\n\/\/Or, assign the value:\n  if ( ($CreatedDateTime = strtotime($CreatedDateTime)) === False )\n  {\n    \/\/An error occured\n  }<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Convert DateTime<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>See<\/strong> <a href=\"https:\/\/ibex.tech\/cloud\/php\/strings\/using-strings-values\">Strings-Values<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Getting Date and Time Elements Using the current DateTime Using a DateTime variable Parameters you can use Calculations Date in # days time Compare Date Time MYSQL Date &amp; Time To set a DateTime field to now use: (Don&#8217;t add single quotes around it) Is String A DateTime? Convert DateTime See Strings-Values<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[21],"tags":[],"class_list":["post-126","post","type-post","status-publish","format-standard","hentry","category-date-and-time"],"_links":{"self":[{"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/posts\/126","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/comments?post=126"}],"version-history":[{"count":38,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/posts\/126\/revisions"}],"predecessor-version":[{"id":5296,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/posts\/126\/revisions\/5296"}],"wp:attachment":[{"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/media?parent=126"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/categories?post=126"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/tags?post=126"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}