/    Sign up×
Community /Pin to ProfileBookmark

Hi,

I am getting the current date and time using date(“Y-m-d, H:i:s”). How do I increment this by 1 day such that output is in “Y-m-d, H:i:s” format? I have tried several implementations of strtotime() but can’t get it to work.

Thanks,

bubbis

to post a comment
PHP

7 Comments(s)

Copy linkTweet thisAlerts:
@eval_BadCode_Nov 27.2010 — $tomorrow = mktime(0, 0, 0, date("m"), date("d")+1, date("y"));

echo "Tomorrow is ".date("m/d/y", $tomorrow).date(" g:i a");

You could also have figured it out using modulo and epoch time.
Copy linkTweet thisAlerts:
@NogDogNov 27.2010 — I'd probably use strtotime() instead of mktime().
[code=php]
$tomorrow = strtotime('+1 day');
echo date("Y-m-d, H:i:s", $tomorrow);
[/code]

Or, if you don't need the $tomorrow variable elsewhere:
[code=php]
echo date("Y-m-d, H:i:s", strtotime('+1 day'));
[/code]
Copy linkTweet thisAlerts:
@bubbisthedogauthorNov 27.2010 — Well I came back to thank eval(BadCode) for the help, and noticed NogDog's response. I had originally tried using strtotime(), which appeared at the time to be a cleaner approach; I just wasn't using it correctly. Anyway, here's what I used according to eval's advice, which worked just fine:
[code=php]
$OneDayAgoPrep = mktime(0,0,0,date("m"),date("d")-1,date("Y"));
$OneDayAgo = date("Y-m-d", $OneDayAgoPrep) . ' ' . date("H:i:s");
[/code]

I think I am going to use NogDog's solution, however.

NOTE: Turns out I needed to decrement the date, not increment it.

Thanks, eval and NogDog, for taking the time to help me.

bubbis
Copy linkTweet thisAlerts:
@tdasthedayDec 21.2010 — using the above example:
[CODE]<?php echo date("Y-m-d, H:i:s", strtotime('+1 day'));?>[/CODE]

How could I limit it to business days only? Not worried about holidays.

Thank you in advance for your advice.
Copy linkTweet thisAlerts:
@NogDogDec 21.2010 — using the above example:
[CODE]<?php echo date("Y-m-d, H:i:s", strtotime('+1 day'));?>[/CODE]

How could I limit it to business days only? Not worried about holidays.

Thank you in advance for your advice.[/QUOTE]


Untested:
[code=php]
$now = time(); // just in case it's a couple microseconds before midnight
$string = (date('N', $now) > 4) ? "next Monday" : "+1 day";
$echo date("Y-m-d, H:i:s", strtotime($string, $now));
[/code]
Copy linkTweet thisAlerts:
@eval_BadCode_Dec 22.2010 — [code=php]

if (date("N") <= 5) echo date("Y-m-d, H:i:s", strtotime('+1 day'));

[/code]


time waits for no one.
Copy linkTweet thisAlerts:
@tdasthedayDec 22.2010 — Thank you Nog and Eval. I will play with those.
×

Success!

Help @bubbisthedog 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.20,
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,
)...