$tuesday_slot = strtotime('next tuesday');
Above code give me unix time for next tuesday.
How do I get the unix time for e.g next tuesday, 1pm.
Thanks!
Easy :
$tuesday_slot = strtotime('next tuesday');
$tuesday_slot = strtotime('+ 13 hours',$tuesday_slot);
echo date("r",$tuesday_slot);
or
$tuesday_slot = strtotime('next tuesday 1pm');
echo date("r",$tuesday_slot);
Related
I should be able to get the first Wednesday of each month, I can do it easily using:
$firstWedNextMonth = date ('d-m-Y', strtotime('first wednesday of next month'));
echo "The first wed of next month is: ".$firstWedNextMonth;
However, considering that the first Wednesday of next month is March 6th, the system must show this date until 3:00:00 on Thursday March 7th, at 3:00:01 instead it must indicate Wednesday, April 3rd. I do not know how to do it. Thank you
I think, this should work. +27 hours is 24 hours + your margin (3 hours). You can test it setting $now to whatever you want, instead of the current time.
$now = time();
$firstWedThisMonth = date ('d-m-Y', strtotime('first wednesday of this month', $now));
$firstWedNextMonth = date ('d-m-Y', strtotime('first wednesday of next month', $now));
$boundaryDateTime = strtotime('+27 hours', strtotime($firstWedThisMonth));
if ($now <= $boundaryDateTime) {
echo "The first wed of next month is: ".$firstWedThisMonth;
} else {
echo "The first wed of next month is: ".$firstWedNextMonth;
}
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 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);
?>
How do I (in an elegant way) get strtotime to select the first upcoming tuesday, and use today if today is tuesday?
I first used
strtotime('next Tuesday');
Then the clock passed midnight monday and strtotime began targeting the NEXT tuesday
strtotime('next Tuesday', strtotime('tomorrow'))
does not seem to change anything (still targets the tuesday next week)
strtotime('this tuesday')
works today, but which tuesday will it target tomorrow?
strtotime("this tuesday") is what you're looking for
//given current datetime of Tue Jul 8 03:40:27
print date('Y-m-d',strtotime('this tuesday')); //2014-07-08
print date('Y-m-d',strtotime('this monday')); //2014-07-14
print date('Y-m-d',strtotime('this wednesday')); //2014-07-09
please review this code
<?php
$day=date('D');
if($day=='r'){
$date=date('Y-m-d');
}else{
$date=date('Y-m-d',strtotime('next tuesday'));
}
echo $date;
?>
One way is to compare this tuesday to today, if it is lower than today so next tuesday is next week :
$today = new DateTime("today");
$tuesday = new DateTime("this tuesday");
if($today > $tuesday){
$tuesday->modify("next tuesday");
}
you can avoid using statement.
<?php
$today = date('D');
$Tuesday= strtotime("Monday"); // change To Monday to test
$secondTuesday=strtotime("next Tuesday",$Tuesday);
echo $today === $Tuesday? date('d.m.Y',$secondTuesday):$today ;
?>
It's monday and I run the following:
$d = date('d-m-Y', strtotime('this tuesday'));
Which gives me date the of tomorrow, 08-07-2014
If i run
$d = date('d-m-Y', strtotime('next tuesday'));
It provides me the same.
But how can i easiest get the next tuesday in the next week (not tomorrow)?
Just try with:
strtotime('this tuesday +1 week')
You can do the following
$d = date('d-m-Y', strtotime('next week tuesday'));
You can add days also to get desire result like :
date('Y-m-d', strtotime('this tuesday +7 days'));