lidds Posted May 25, 2006 Share Posted May 25, 2006 What I want to be able to do is add 1 week onto an existing date e.g.[code]$date = "1978-10-15";// here add code to add 1 week onto the above date[/code]The date format I am using is "Y-m-d" and the date could be any stored date i.e. not the current dateCan anyone help.....Thanks in advanceSimon Link to comment https://forums.phpfreaks.com/topic/10451-how-to-add-a-week-onto-a-date/ Share on other sites More sharing options...
kenrbnsn Posted May 25, 2006 Share Posted May 25, 2006 There are a number of different ways to do this, here are two:[list][*]Use the strtotime() function:[code]<?php$date = "1978-10-15";$newdate = date('Y-m-d',strtotime($date . ' + 1 week'));echo $newdate;?>[/code][*]Convert the date to the number of seconds since 1970-1-1 and add the number of seconds in a week (604,800)[code]<?php$date_secs = strtotime("1978-10-15");$new_date = date_secs + 604800;echo date('Y-m-d',$new_date);?>[/code][/list]The above will only work with dates since 1-1-1970 in most cases.Ken Link to comment https://forums.phpfreaks.com/topic/10451-how-to-add-a-week-onto-a-date/#findComment-38989 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.