This question already has answers here:
Add number of days to a date
(20 answers)
Closed 9 years ago.
I want to add 30 days to current date time.
for example :
$today = date("Y-m-d H:i:s");
I want to generate new date time , I want to add 30 days to $today date time.
How I do that?
UPDATE:
special for those 5 supernova smart guys: John Conde, Woot4Moo, cryptic ツ, moonwave99, Marc B ; yes it is duplicate but people formulate their question differently and this post may help other people to find faster than other post which was formulated differently but have same main idea. I would not mark this as trash, people do think different and use different key words during searching, and somebody may find this post quicker than the other duplicate post... have fun!
$thirty_days_ahead = date('Y-m-d H:i:s', strtotime("+30 days") )
try this
$today = date('Y-m-d H:i:s',strtotime("+30 days"));
strtotime("+30 days")
should be the most simple way to do it.
Related
This question already has answers here:
PHP Strtotime without current time?
(2 answers)
Closed 4 months ago.
I have an Unix timestamp like this 1660293621 (2022-08-12 8:40). I want to get next 2 days not counting current date. I expect the result to be 2022-08-15 00:00.
I tried
strtotime("+3 Days", $current_date)
but it returns 2022-08-15 8:40, not 00:00
How can I get that in PHP? Thank you~
$Today=date('y:m:d');
// add 3 days to date
$NewDate=Date('y:m:d', strtotime('+3 days'));
Reference:
Increase days to php current Date()
I figured it out, just add 0:00 will help
$next2days = strtotime("+3 days 0:00", $current_date);
This question already has answers here:
PHP Adding 15 minutes to Time value
(9 answers)
Closed 4 years ago.
I want to add a specific period like 2 hours to only time.
BUT only TIME. There will be no date related issue.
Like my time is 02:00:00
And I want to add 1 hour to this time.
So, the result will be 03:00:00
Is there any PHP built-in function like strtotime()?
I don't want explode related function for this like explode(":", $time)
Is it possible? Please help someone.
Try
$new_time = date("H:i:s", strtotime("+ 1 hours"))
or if you would just like the timestamp:
strtotime("+ 1 hours")
This question already has answers here:
Subtract one second from a given time
(2 answers)
Closed 8 years ago.
I writing a code for subtract seconds from a time using php. i have date which assigned to variable , i need to subtract seconds from that date.
$date="2014-03-16 17:40:27";
echo date("Y-m-d H:i:s", strtotime($date) - strtotime("-600 seconds"));
but this gives me dates on 1970S, i search everhere and didn't found a answer which matched for my question. can anyone help me to fix this little code
strtotime() gives you a timestamp in seconds. Don't make another timestamp to subtract from it, just take 600 from it:
echo date("Y-m-d H:i:s", strtotime($date) - 600);
//2014-03-16 17:30:27
This question already has an answer here:
Week number and Week day
(1 answer)
Closed 9 years ago.
If anyone has an idea how can I calculate a calendar week depending on given date in php, for example 06.06.2013 (format like this 2013-06-06). is calendar week 23. I was searching for the solution all morning and found nothing useful. Any help or link, anything would be appreciated. Thank you
Use date("W")
echo date("W", strtotime('2013-06-06'));
See it in action
date('W') should give you the week of the year. RTM
If you don't have your time as a unix timestamp you can use strtotime() first and pass it as the second parameter
ex. date('W',strtotime($my_time_string))
You can see the PHP manual here
Like this:
$time = '2013-06-06';
$calendar_week = date('W', strtotime($time));
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
PHP:find day difference between two date(“YmdHis”) reture
What I want to do is to get day from database, current date. And check if difference between them > 1 day:
$curdate= date("Y-m-d H:i:s");
$dbdate is value stored in datetime format in db.
$dif=$curdate-dbdate;
How to check if $dif>1 day ??
Assuming the stored date is expressed in the same time zone as the server, you can convert it to a timestamp using strtotime, and compare it to strtotime("-1 day"):
if (strtotime($dbdate) < strtotime("-1 day"))
frobnicate();
You can get just the day from each date.
$day = intval($curdate= date("d"));
This will get the day as an in. Do the same for the time of the data base and you get two integer representing the day. Using that you can calculate how many days have pass.
Beware that the last line should look like this:
$dif = abs($curdate-$dbdate);