set javascript cookies using server timestamp


   I want to assign server's time calculated using php  as expiration date for javascript cookie.
  I have timestamp in php which i want to use to set expiration date of javacsript cookies...but javascript cookie is not taking that timestamp...I would like to set cookie for 1 day ...but requirement is if user login at Tue  Nov 22 17.45.33  UTC so my cookie's expiration date should be Wed Nov 23 00.00.00 UTC ..means exact 1 day but not 24 hrs..It shoud set to 00.00.00 clock time  of next day.

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Get your timestamp in php using strtotime("+1 Day");


$var = strtotime("+1 Day");
echo date("m d Y H:i:s", $var);

Outputs: 11 25 2004 00:00:00

You should then just be able to write that timestamp in your JS code, eg:

<script langauge="JavaScript">
var stamp = <?php echo strtotime("+1 Day"); ?>


Although i have to wonder why you are using JS to set the cookie, i seem to recall the client side code to set a cookie is quite lengthy comparred to the signle line with PHP.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
You can set cookies via php like to the desired expire-time like this:

$expire = mktime(0,0,0, date('m'), date('d') +1, date('Y'));
foreach ($_COOKIE as $n => $v) {
    setcookie($n, $v, $expire);
If you need it in the specific format of Wed Nov 23 00.00.00 UTC rather then just a timestamp you could use:
<?php echo date("D M d H.i.s \U\TC",strtotime("+1 Day")); ?> which outputs: Wed Nov 24 00.00.00 UTC
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.