/    Sign up×
Community /Pin to ProfileBookmark

Should be pretty easy but I’m stuck. Get date("m/d/y") – 1?

Right now I have this:

[CODE]$mydate = date(“m/d/y”);[/CODE]

Which gives me today’s date in the correct format. What I need is yesterday’s date. I tried:

[CODE]$mydate = date(“m/d/y”)-1;[/CODE]

but that just returns 0.

I’m looking at the PHP.Net page for the date function but can’t find anything that helps me.

Anyone?

to post a comment
PHP

5 Comments(s)

Copy linkTweet thisAlerts:
@skywalker2208Jan 23.2009 — strtotime is what you need. It will convert the date into a unix timestamp then you can use the date function to format it. I have copied and pasted some of the examples from the page below and you should be able to figure it from there.

[code=php]
echo strtotime("now"), "n";
echo strtotime("10 September 2000"), "n";
echo strtotime("+1 day"), "n";
echo strtotime("+1 week"), "n";
echo strtotime("+1 week 2 days 4 hours 2 seconds"), "n";
echo strtotime("next Thursday"), "n";
echo strtotime("last Monday"), "n";
[/code]
Copy linkTweet thisAlerts:
@aj_nscJan 23.2009 — [code=php]
$YesterdayUnixtime = mktime()-86400; //gets the unixtime and subtracts 86400 seconds - i.e. 1 day
$mydate = date("m/d/y",$YesterdayUnixtime)
[/code]
Copy linkTweet thisAlerts:
@NogDogJan 23.2009 — "Yesterday" is one of the strings strtotime() recognizes:
[code=php]
$mydate = date('m/d/Y', strtotime('yesterday'));
[/code]
Copy linkTweet thisAlerts:
@xvszeroauthorJan 23.2009 — Got it.

THX.
×

Success!

Help @xvszero 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.19,
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,
)...