I would like to set a cookie with PHP that has to expire at the end of the month.
How can I get the number of seconds until the end of the month?
Thank you.
You can use time() to get the number of seconds elapsed since the epoche. Then use strtotime("date") to get the number of seconds to your date. Subtract the two and you have the number of seconds difference.
This will give you the last second of the month:
$end = strtotime('+1 month',strtotime(date('m').'/01/'.date('Y').' 00:00:00')) - 1;
This will give you now:
$now = time();
This will give you the distance:
$numSecondsUntilEnd = $end - $now;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With