Today 05/18/2011 If i do

echo date("H:i m/d/Y", strtotime("tomorrow"));

i get 00:00 05/19/2011 as it should be but if i use the same function in setcookie like:

setcookie("wls_yesterday_review", 'completed', strtotime('tomorrow'),'/','myhost.com');

My cookie will expire on 05/18/2011 at 09:00PM

Im not sure what im doing wrong but i tested different ways and different times and i always get the same result

i want to expire the cookie at 00:00 of the following day. If today is 05/18 10:00am i want it to expire on 05/19 00:00

Thanks guys

Member Avatar for diafol

Yep, same here with your code, I get 00:00 with echo, and when I check the cookie, I get 23:00 (i.e. 1 hour before). As we are currently in DST mode in the UK, I wonder whether this has got anything to do with it.

Are you at a different timezone to GMT/UTC? I noticed Buenos Aires is [GMT/UTC - 3 hours]. Is this why? It follows the same pattern as I get in that case 00:00 05/19/2011 - 3 hours = 5/18/2011 at 09:00PM.

//EDIT
Ah, just thought, does the pc have to have a 'standard time' cookie? Seeing as webpages can change their timezones easily, there must be a standard/uniform way of timing the expiry of cookies. So, I assume that's it. I shall have to investigate further.

Hi, yes im in GTM -3 and its probably what you say, but im not sure why or how to avoid the problems as users will have different time zones.

The problem is that cookies should act the same way as the echo does. In that case we will be all happy :D
I will investigate aswell.

Member Avatar for diafol

Huh, would you believe it, my page was set to 'Europe/Berlin' when I tested it with

date_default_timezone_get()

Change the TZ using:

date_default_timezone_set('America/Buenos_Aires');

See if it does the trick, it did for me.

But in that case it will only work for America /Buenos aires people.
What about if i have an australian visitor ? How can i be sure that the cookie will expire at the end of his day and not at the end of mine ?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.