I was wondering if it was possible to format todays date to below format:
YYYY-MM-DDTHH:MM:SS
It's important that the "T" is preserved, like this:
2017-07-20T00:00:00
Below I have:
$invoice_date = date('Y-m-d H:i:s');
I can't figure out how to add the "T" in between.
Change DD-MM-YYYY to YYYY-MM-DD In the below example, we have date 17-07-2012 in DD-MM-YYYY format, and we will convert this to 2012-07-17 (YYYY-MM-DD) format. $orgDate = "17-07-2012"; $newDate = date("Y-m-d", strtotime($orgDate)); echo "New date format is: ".
php $date1 = "2019-05-16"; $timestamp1 = strtotime($date1); echo $timestamp1; // Outputs: 1557964800 $date2 = "16-05-2019"; $timestamp2 = strtotime($date2); echo $timestamp2; // Outputs: 1557964800 $date3 = "16 May 2019"; $timestamp3 = strtotime($date3); echo $timestamp3; // Outputs: 1557964800 ?>
P - Difference to Greenwich time (GMT) in hours:minutes (added in PHP 5.1.3) T - Timezone abbreviations (Examples: EST, MDT) Z - Timezone offset in seconds. The offset for timezones west of UTC is negative (-43200 to 50400) c - The ISO-8601 date (e.g. 2013-05-05T16:34:42+00:00)
Re: convert Date from YYYY-MM-DD to MM/DD/YYYY in jQuery/JavaScript. var tempDate = new Date("2021-09-21"); var formattedDate = [tempDate. getMonth() + 1, tempDate. getDate(), tempDate.
T
is a format character so you can't use it directly. Escape it (\T
) to get a literal T
character:
http://php.net/manual/en/function.date.php
You can prevent a recognized character in the format string from being expanded by escaping it with a preceding backslash.
$invoice_date = date('Y-m-d\TH:i:s');
$invoice_date = date('Y-m-d\TH:i:s');
You can create an object of the DateTime and set the Timezone. You can see a list of Timezone strings here. http://php.net/manual/en/timezones.php
$invoice_date = (new \DateTime('America/New_York'))->format('Y-m-d\TH:i:s');
echo $invoice_date;
Hope this helps
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With