![]() |
Most efficient way of playing with dates?
So I've got this unix timestamp from the past which I needed to convert into a date:
PHP Code:
PHP Code:
PHP Code:
Does anyone see something totally wrong? Or maybe an easier alternative? Thank you. |
I dont use strtotime, unix timestamps are seconds since the unix epoch (1/1/1970), so 90 days from now would be $time + (60*60*24*90), the remainder of days would be time - $original_time / (60/60/24)
Just my preference. |
This is how I modified your code to work:
PHP Code:
|
As an aside, you don't need to do
date('z', strtotime(date('Y-m-d H:i'))) to get today's day of the year. Simply skip the second argument to use the current time stamp: date('z').Personally, I'd prefer working with the timestamps themselves and only use the date() function for outputting friendly strings. Something like the the following: php Code:
|
Quote:
|
The most efficient way of working with dates in PHP it's by operating on the date timestamp and just output the formatted one (yes I am agreeing with Salathe) :D
|
Thanks for everyones input.
Now that I think about it, playing with the timestamp itself seems better. :-) |
| All times are GMT. The time now is 10:45 AM. |
Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0