I am using the following code to transform a universal time code into something a little more user friendly.
$meeting_time = date('g:i a', strtotime($time_date_data));
But now I need to subtract 6 hours from meeting_time. Should I do it after the code above or can I work it into the same date function?
Something like:
$meeting_time = date('g:i a' - 6, strtotime($time_date_data));
Code for converting a string to dateTime $date = strtotime ( $input ); echo date ( 'd/M/Y h:i:s' , $date );
The strtotime() function parses an English textual datetime into a Unix timestamp (the number of seconds since January 1 1970 00:00:00 GMT). Note: If the year is specified in a two-digit format, values between 0-69 are mapped to 2000-2069 and values between 70-100 are mapped to 1970-2000.
You can use DateTime::modify to add time, but I would just do time()+10800 . Show activity on this post. $time = new DateTime("+ 3 hour"); $timestamp = $time->format('Y-M-d h:i:s a');
If you want to use the PHP function strtotime to add or subtract a number of days, weeks, months or years from a date other than the current time, you can do it by passing the second optional parameter to the strtotime() function, or by adding it into the string which defines the time to parse.
$meeting_time = date('g:i a', strtotime($time_date_data) - 60 * 60 * 6);
String-to-time (strtotime) returns a Unix Time Stamp which is in seconds (since Epoch), so you can simply subtract the 21600 seconds, before converting it back to the specified date format.
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