Parse a UTC date, output local datetime

I have already read How to get local time in php? and similar questions, but here I want to do the contrary: With a given datetime in UTC (e.g. 2021-03-31 23:45:00), how to output the date in local …

gmdate 12 hours off

I’m trying to get the GMT to send with an API request however my time is off from the actual GMT. Right now the GMT is 6:40 PM Friday, November 20, 2020. However when I run gmdate(“Y-m-dTh:i:sZ&…

PHP & MySQL DateTime – Timezone Handling

I want to store a DateTime value in my database (MySQL 5.7). I am trying to figure out the best way to handle time zones. From a glance it seems that MySQL only takes DateTime in the format of Y-m-d H:…

PHP Datetime Formatting

I am using an external API to fetch data on posts and its publish date format seems unusual: “created_at” : “Mon Jul 27 14:30:53 -0500 2020” I can pretty know when it was …

Find records between two time slots in php

i have time slots like $timeslot = [’09:00-10:00′, …. ’23:00-00:00′, ’00:00-01:00′]; I have records with updated time as 23:15:00, 23:30:00, 00:15:00, 09:15:00 etc. What i’m trying to find is the …

How to display days and hours with date() in php

I have a timestamp which calculates remaining time between 2 dates. $job_expiration = strtotime($job[‘job_expiration’]) – time(); like so. Right now, I’m showing only 1 day or 2 days with the date()…

Setting just the year with PHP DateTime

With PHP DateTime you can use methods such as ->modify() ->add() and ->sub() to manipulate the current DateTime object. There are also ->setDate() and ->setTime() methods which allow …

Issue with getting the day of a month with the week day and year

I’m trying to get the day of a month with this code: // your input $month = “September”; $year = “2013”; $dayWeek = “Friday”; $week = 2; // create a date object $date = new …

PHP – Can’t set correct DateTimeZone to DateTime

Background I have a list of events that are set to a certain (UK) time. I want users to see the time of the event in their local time. For example: if an event starts at 20:30 UK time a user from the …

How to format an UTC date to use the Z (Zulu) zone designator in php?

I need to display and handle UTC dates in the following format: 2013-06-28T22:15:00Z As this format is part of the ISO8601 standard I have no trouble creating DateTime objects from strings like …