Jump to content

How to add a week onto a date...


lidds

Recommended Posts

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 date

Can anyone help.....

Thanks in advance

Simon
Link to comment
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.