I need to generate a timestamp for an exact date in the next month.
I want to generate the timestamp for the 10th of the next month automatically.
I tried playing around with strtotime but couldn't work it out.
Thanks,
Try this:
echo date('Y-m-d', strtotime(date('Y-m-10'). '+1 month'));
Related
It is giving correct date but not the correct day value.Why..?
What I want day is the date for monday for the current week which can be generated on any day of the week. so what I did was, I'm taking the today's day and comparing with (Mon,Tue.... Sun) and respectively creating a timestamp using
You can use date("Y-m-d",strtotime("monday")); to find out next Monday.
To find Monday from any day of the week you can try this-
$date="2018-08-01"; //any day of the week
$day=date("N",strtotime($date));
if($day>1){
$date=date("Y-m-d",strtotime("$date -1 week"));
}
echo date("Y-m-d",strtotime("$date monday"));
Didn't sure what you really want but if you want current day date simply use getdate() function
I need to find the date number for the first day of the current week. For example if the date is 05/06.2015 I want to get as a result 29/05/2015 where Monday is the firs day of the week. I'm not very familiar with PHP date functions because I'm new at it. Can someone show me how to find it? Thanks!
strtotime is a powerful function.
echo date("j/n/Y", strtotime('monday this week'));
So I am having a little trouble getting today's midnight date using the midnight time using the time() function.
It is a little confusing for me when I explain to my peers on the timestamp I want. What I need is, if today is wed-06-Aug-2014 at 9:00pm , then I want the time at wed-06-Aug-2014 00:00.
Any help?
Just use relative date and time formats:
echo date('D-d-M-Y H:i', strtotime('midnight'));
Demo
Suppose I pull a field from the database, a timestamp field.
How do I get the Unix Timestamp, 1 month in the future, from that timestamp field?
My brain is a bit tired, so I need a bit of a re-jogging.
$newDate = strtotime('+1 month',$startDate);
Using strtotime() you can pass it '+1 month' to add a context sensitive month.
I would use the strtotime() function, to add +1 month to your timestamp :
$future = strtotime('+1 month', $current_time);
With strtotime(), you don't have to think yourself about stuff like "some month avec 30 days, and others have 31", or "february sometimes has 28 days and sometimes 29".
After all, adding one month to a date is a bit harder that adding 30*24*3600 seconds...
You could also work with the DateTime class, and methods such as DateTime::modify() or DateTime::add().
Wouldn't
strtotime('+1 month', $value_from_db);
work?
Depends on the database.
MySQL has TIMESTAMPADD
Postgre lets you just add INTERVAL 1 MONTH.
Oracle... is annoying. But you can find out how to do that here.
(Don't know the others, sorry)
Of course there is also strtotime('+1 month', $current_time); in PHP. Of course, strtotime is so incredibly easy you might consider it cheating ;-).
How about something like:
tm *currTime = localtime(timestamp);
currTime->tm_mon++;
timestamp = mktime(currTime);
I'm trying to get the starting monday date of the actual week we are in. Like we are July 15th and would like to have the result with strtotime to return July 11th...
I've tried
strtotime("-1 weekdays");
Without luck... What could be the function for the actual week please.
Thanks
$timestamp = strotime('monday this week');
Will give you Monday! ;)
Did none of these help you to find your answer?
Get first day of week in PHP?
Finding First day of week via php
First date of a week