{"id":3880,"date":"2022-11-21T10:50:12","date_gmt":"2022-11-21T10:50:12","guid":{"rendered":"https:\/\/info.documotor.com\/?page_id=3880"},"modified":"2023-01-25T10:23:01","modified_gmt":"2023-01-25T10:23:01","slug":"to_datetime","status":"publish","type":"page","link":"https:\/\/info.documotor.com\/?page_id=3880","title":{"rendered":"To_datetime"},"content":{"rendered":"\n<p>Converts a string to a standardized datetime object. <\/p>\n\n\n\n<h3>Syntax<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"\">datetime to_datetime(string $data, string $format, string $culture)<\/code><\/pre>\n\n\n\n<p>Converts <code>$data<\/code> string, formatted as defined in <code>$format<\/code> to default date\/time by <code>$culture<\/code>. <\/p>\n\n\n\n<h3>Parameters<\/h3>\n\n\n\n<p><strong>$data:<\/strong> The input string.<\/p>\n\n\n\n<p><strong>$format:<\/strong> Definition of the input string. This&nbsp;is expected as a&nbsp;<a href=\"https:\/\/docs.microsoft.com\/en-us\/dotnet\/standard\/base-types\/standard-date-and-time-format-strings\">datetime format<\/a>&nbsp;string to use for parsing.<\/p>\n\n\n\n<p><strong>$culture:<\/strong> The desired date\/time output format. This should be a&nbsp;<em>language culture name<\/em>, based on&nbsp;<a href=\"https:\/\/en.wikipedia.org\/wiki\/List_of_ISO_639-1_codes\">ISO-639-1<\/a>&nbsp;(ie. \u2018<strong>en-US<\/strong>\u2018, \u2018<strong>es-ES<\/strong>\u2018).<\/p>\n\n\n\n<h3>Example<\/h3>\n\n\n\n<pre title=\"Data\" class=\"wp-block-code\"><code lang=\"json\" class=\"language-json line-numbers\">{\n  \"startDate\": \"2021-02-21 12:00:00Z\",\n  \"endDate\": \"3 March, 2021\"\n}<\/code><\/pre>\n\n\n\n<pre title=\"Transformation\" class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash line-numbers\">{\n  formattedStartDate:to_datetime(startDate, 'u', 'en-US'),\n  formattedEndDate:to_datetime(endDate, 'd MMMM, yyyy', 'en-US')\n}<\/code><\/pre>\n\n\n\n<pre title=\"Output\" class=\"wp-block-code\"><code lang=\"json\" class=\"language-json line-numbers\">{\n  \"formattedStartDate\": \"2021-02-21T12:00:00\",\n  \"formattedEndDate\": \"2021-03-03T00:00:00\"\n}<\/code><\/pre>\n\n\n\n<p>In this example the start date and end dates are formatted differently. <code>startDate <\/code>conforms to the universal sortable datetime format so &#8216;u&#8217; is defined as $format. endDate is formatted as d MMMM, yyyy.<\/p>\n\n\n\n<h3>Notes<\/h3>\n\n\n\n<p>This function is often used in conjunction with the <a href=\"https:\/\/info.documotor.com\/?page_id=3753\" data-type=\"page\" data-id=\"3753\">format function<\/a> to convert any input date format to any output date format.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Converts a string to a standardized datetime object. Syntax Converts $data string, formatted as defined in $format to default date\/time by $culture. Parameters $data: The input string. $format: Definition of the input string. This&nbsp;is expected as a&nbsp;datetime format&nbsp;string to use for parsing. $culture: The desired date\/time output format. This should be a&nbsp;language culture name, based [&hellip;]<\/p>\n","protected":false},"author":11,"featured_media":0,"parent":271,"menu_order":192,"comment_status":"closed","ping_status":"closed","template":"","meta":[],"_links":{"self":[{"href":"https:\/\/info.documotor.com\/index.php?rest_route=\/wp\/v2\/pages\/3880"}],"collection":[{"href":"https:\/\/info.documotor.com\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/info.documotor.com\/index.php?rest_route=\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/info.documotor.com\/index.php?rest_route=\/wp\/v2\/users\/11"}],"replies":[{"embeddable":true,"href":"https:\/\/info.documotor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3880"}],"version-history":[{"count":9,"href":"https:\/\/info.documotor.com\/index.php?rest_route=\/wp\/v2\/pages\/3880\/revisions"}],"predecessor-version":[{"id":3916,"href":"https:\/\/info.documotor.com\/index.php?rest_route=\/wp\/v2\/pages\/3880\/revisions\/3916"}],"up":[{"embeddable":true,"href":"https:\/\/info.documotor.com\/index.php?rest_route=\/wp\/v2\/pages\/271"}],"wp:attachment":[{"href":"https:\/\/info.documotor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3880"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}