I am working with php5.5.1.
//date_default_timezone_get = UTC
date('d/m/Y ... H:i:s', 1400444640); // = Sunday 18/05/2014 ... 20:24
How do I get the current Monday of that week?
date('d/m/Y ... H:i:s', (strtotime('Monday this week', 1400444640))); // 19/05/2014 ... 00:00
Why do not I get a date Monday 12? How I can get it correctly?
If you want it to be the twelfth then you need to ask for the monday of the previous week.
date('d/m/Y ... H:i:s', (strtotime('previous week monday', 1400444640)));
Related
Is there an easy way to get last week's, say, Monday? If today is Tuesday, I do not want yesterday's Monday. Rather, I want the Monday 8 days ago (last week's Monday). Then I want that Monday's proceeding Sunday. Basically, I'm trying to get the date range for last week, Monday to Sunday.
This doesn't always work right:
date('Y-m-d', strtotime('last Monday')
Suggestions?
You can use “this week” format:
$monday = strtotime( 'this week', strtotime( '7 days ago' ) );
$sunday = strtotime( '+ 6 days', $monday );
3v4l.org demo
“this_week” returns monday of previous week, then — adding 6 days — you obtain the monday of relative week.
The strtotime function accepts the current date as a parameter.
http://php.net/manual/en/function.strtotime.php
Just pass in strtotime('last Sunday') as the parameter to get a weekday of the last full week.
$beginning_of_week = strtotime('last Sunday');
$result = date('Y-m-d', strtotime('last Monday', $beginning_of_week));
echo $result;
I'm having a weird problem. When I do strtotime it's not considering the hours part of the original date, and it's always returning midnight. I tried to research but I couldn't find anything specific.
Is there something I'm missing?
$original_date = "2015-08-07 02:00:00";
$next_date = date('Y-m-d H:i:s', strtotime("monday this Week +1 week", strtotime($original_date)));
It returns $next_date as 2015-08-14 00:00:00
Try this, add time which you want to retrieve in next date,.
$original_date = "2015-08-07 02:00:00";
echo $next_date = date('Y-m-d H:i:s', strtotime("monday this Week 02:00:00 +1 week", strtotime($original_date)));
monday this week +1 week assumes you’re looking for midnight of the monday of the week of the passed in time. If you want to preserve the hours part of the time, then you can append it to your date format because it should always be the same as in $original_date
date('Y-m-d ' . date('H:i:s', strtotime($original_date)), strtotime("monday this Week +1 week", strtotime($original_date)));
When you use monday in strtotime you're resetting the time back to 00:00:00. You will have to explicitly pass the time in either your date or strtotime to get your desired behavior. See this same question for a similar issue.
$next_date = date('Y-m-d H:i:s', strtotime("monday this Week +1 week " . date('H:i:s', strtotime($original_date)), strtotime($original_date)))
$date = strtotime('2018-08-14 02:00:00');
$next_date = date('Y-m-d H:i:s', strtotime("monday this Week 02:00:00 +1 week", $date)); // 2018-08-20 02:00:00
I have a problem in PHP:
How can I get the next friday of a given day?
E.g.
What's the date of next friday following monday 6th April 2015?
Is there a way to pass as a parameter the wanted day to strtotime( "next friday")?
Ok, got it! Thanks to all!
The problem with my dates is that they formated like d/m/Y, and I was messing it all up.
$dt = explode("/", $_SESSION['conj']['dtEnd'][0]);
$newDate = $dt[2] ."-".$dt[1]."-".$dt[0];
$nextFriday = date ('d/m/Y', strtotime("next friday", strtotime($newDate)));
<?php
$time = strtotime('Monday, April 6, 2015');
$next = strtotime('next friday, 11:59am', $time);
echo date('l, F j', $next);
?>
I'm trying to get a date that comes next Monday at night 00:01 am. I'm using the following lines:
date('Y-m-d h:i:s', strtotime(**'next monday, 01:01am'**, strtotime(date("Y-m-d h:i:s"))))
This gives me the proper output:
2014-05-19 01:01:00
But if I try to write:
date('Y-m-d h:i:s', strtotime(**'next monday, 00:01am'**, strtotime(date("Y-m-d h:i:s"))))
I'm getting:
1970-01-01 05:30:00
Please tell me what is wrong here.
00:01 am is not correct Use 12:01 am
Try this:
date('Y-m-d h:i:s', strtotime('next monday, 12:01am', strtotime(date("Y-m-d h:i:s"))));
It will give you 2014-05-19 12:01:00
Demo
I am trying to get the timestamp of the first day of the month at 00:00:00.
For example, the timestamp of Jan 01 2012 00:00:00
I'm doing this:
$test_month = time(); // Seconds
$test_month = date('M', $test_month); // This month
$test_month = strtotime($test_month); // Timestamp of this month
echo $test_month;
This is returning zero hour of the current day of the month, not the start of the month.
Any suggestions?
Try this:
echo date( 'F jS Y h:i:s A', strtotime( 'first day of ' . date( 'F Y')));
This will output:
June 1st 2012 12:00:00 AM
Try this
$time = strtotime(date('Y-m-01 00:00:00')); // == 1338534000
Which translates to:
$date = date('Y-m-d H:i:s', $time); // == 2012-06-01 00:00:00
Read the PHP manual on the date() and time() functions.
echo date("Y-m-d 00:00:00", strtotime("first day of this month"));
This outputs:
2017-05-01 00:00:00