/    Sign up×
Community /Pin to ProfileBookmark

how to get get the next/previous date

Hi

Assuming I have a specific date in 3 variables:
$day (1-31)
$month (1-12)
and $year (1900-2100)

I would like to know what the date would be one day from now or what it was the day before.
Or what would be the date one month from now and one month before
Or what would be the date one year from now and one year before

Is there a way to get this information using Date/Time PHP functions without resulting to explicit calculations (if I am in February there are 28 days, except…)

For example, if the date is:
$day = 31
$month = 3
$year = 2005
Then one day from now it would be 1/4/2005

regards

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@JonaMar 15.2005 — [font=trebuchet ms]See [/font][font=courier new][url=http://us2.php.net/mktime]mktime()[/url][/font][font=trebuchet ms].[/font]
Copy linkTweet thisAlerts:
@JaelanMar 15.2005 — Another function to try out is [URL=http://us2.php.net/strtotime]strtotime()[/URL]

If you do the line:

[code=php]echo date("F d, Y", strtotime("+1 day"));[/code]

It's nice!

Hope that helps,

Jaelan
Copy linkTweet thisAlerts:
@jasongrauthorMar 15.2005 — thanks, function strtotime() was indeed the one I used:
[code=php]
$futureTimeStamp = strtotime("+1 day", mktime(0, 0, 0, $month, $day, $year));
[/code]
×

Success!

Help @jasongr spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...