I currently have php returning the current date/time like so: What I’d like to do is have a new variable $new_time equal $now + $hours, where $hours is a number of hours ranging from 24 to 800. Any suggestions? Answer You may use something like the strtotime() function to add something to the current timestamp. $new_time = date(“Y-m-d H:i:s”, strtotime(‘+5
Tag: date
PHP get UK local time from Server in different time zone
I have a web server which I do not know what the time zone is set to. it is now 10:49am in the UK, but when I run the following: The server returns the following time. Now I don’t want to just “Add” one hour onto the time because the time still needs to be correct when time moves forward
PHP checkdate variants
I found a php function checkdate() , but strangely enough it only seems to accept data in format of int $month , int $day , int $year. However I am passing the date as a string (example “2012-06-13”) …
Get most recent date from an array of dates in “Y-m-d H:i:s” format
I have the array of dates in Y-m-d H:i:s format like: I would like to know the most recent date. In other words, today is June 13th 2012, which datetime is closest to today’s date? From my sample array, I am expecting 2012-06-11 08:30:49. How can I do that? Answer Do a loop, convert the values to date, and store
Getting start and end date of a PHP DatePeriod object?
How can i get the start and end date of a DatePeriod object? Answer DatePeriod only implements the Traversable interface and has no other methods to either access elements or retrieve them. You can do something easy to get start/end dates:
PHP Date Function Seven days previous
I am trying to use PHP’s Date Function to get the date of 7 days earlier in YYYY-MM-DD format. when i try i get an error Answer Use the strtotime method provided by PHP. date(‘Y-m-d’, strtotime(‘-7 days’)) Thanks to @lonesomeday for pointing out my mistake in the comments 😉
PHP string date + 1 day equals?
I have a date which is saved in a regular string. // format = DD-MM-YYYY $date = “10-12-2011”; How can I get the date-string +1 day so: 11-12-2011?
subtract 6 hours from date(‘g:i a’, strtotime($time_date_data));
I am using the following code to transform a universal time code into something a little more user friendly. 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: Answer String-to-time (strtotime) returns a Unix Time Stamp which is in
Get current date, given a timezone in PHP?
I want to get todays date given a time zone in Paul Eggert format(America/New_York) in PHP?
How can I divide a date range by number of months?
My dilemma is that if I request more than 6 months or so ( I do not know the approximate number ) from my webservices ( which gets called via JS ), I get nothing back. In other words, I have to limit it to 6 months. So let’s consider this scenario: I need to split this up by 6