Get the Date as '2023-06-13T00:55:44+05:30' in PHP


By Faraz - June 13, 2023

Learn how to obtain a date in the format '2023-06-13T00:55:44+05:30' using PHP. Step-by-step guide for date manipulation in PHP.

To get the current date in the format '2023-06-13T00:55:44+05:30' in PHP, you can use the following code:

date_default_timezone_set('Asia/Kolkata'); // Set the desired timezone

$currentDate = date('Y-m-d\TH:i:sP'); // Format the date

echo $currentDate; // Output: 2023-06-13T00:55:44+05:30

In this code, date_default_timezone_set is used to set the desired timezone. If needed, you can replace 'Asia/Kolkata' with your specific timezone.

Then, the date is used to format the date according to the specified format. In this case, 'Y-m-d\TH:i:sP' is used, where:

  1. 'Y' represents the 4-digit year
  2. 'm' represents the 2-digit month
  3. 'd' represents the 2-digit day
  4. 'T' represents the literal 'T'
  5. 'H' represents the 2-digit hour in 24-hour format
  6. 'i' represents the 2-digit minute
  7. 's' represents the 2-digit second
  8. 'P' represents the timezone offset in the format '+05:30'

Finally, echo is used to output the formatted date.

I hope you found the above information helpful. Please let me know in the comment box if you have an alternate answer πŸ”₯ and you can support me by buying me a coffee.

And don’t forget to sign up to our email newsletter so you can get useful content like this sent right to your inbox!

Faraz 😊

End of the article

Subscribe to my Newsletter

Get the latest posts delivered right to your inbox

Latest Post