tobeyt23 Posted April 20, 2009 Share Posted April 20, 2009 Which is the better way to go? Quote Link to comment https://forums.phpfreaks.com/topic/154916-php-time-vs-mysql-now/ Share on other sites More sharing options...
Maq Posted April 20, 2009 Share Posted April 20, 2009 Which is the better way to go? Depends on your application... Quote Link to comment https://forums.phpfreaks.com/topic/154916-php-time-vs-mysql-now/#findComment-814828 Share on other sites More sharing options...
PFMaBiSmAd Posted April 20, 2009 Share Posted April 20, 2009 Since time() returns a Unix Timestamp, which must be converted and is subject to the timezone settings at the time it is converted to be usable for almost anything in a human form, and NOW() returns a DATETIME value which will always be the value it has been set to and can easily be formatted (not requiring a conversion) to any format, the answer would obviously be mysql NOW() for most uses. Quote Link to comment https://forums.phpfreaks.com/topic/154916-php-time-vs-mysql-now/#findComment-814829 Share on other sites More sharing options...
The Little Guy Posted April 20, 2009 Share Posted April 20, 2009 Well.... time() is a unix time stamp Whereas NOW() returns a date format: '2007-12-15 23:50:26' time() will allow for you to easily display time according to a users timezone. Quote Link to comment https://forums.phpfreaks.com/topic/154916-php-time-vs-mysql-now/#findComment-814831 Share on other sites More sharing options...
premiso Posted April 20, 2009 Share Posted April 20, 2009 Since time() returns a Unix Timestamp, which must be converted and is subject to the timezone settings at the time it is converted to be usable for almost anything in a human form, and NOW() returns a DATETIME value which will always be the value it has been set to and can easily be formatted (not requiring a conversion) to any format, the answer would obviously be mysql NOW() for most uses. Not to mention unix timestamps have a date range. After 2037, unix time cannot calculate the date thus is obsolete. MySQL time will do just fine from now till the next 0 is added on. I prefer the DATETIME in MySQL as not only is it readable, it will not become obsolete for sometime. Quote Link to comment https://forums.phpfreaks.com/topic/154916-php-time-vs-mysql-now/#findComment-814833 Share on other sites More sharing options...
tobeyt23 Posted April 20, 2009 Author Share Posted April 20, 2009 Thanks I have been using NOW() for a while. Quote Link to comment https://forums.phpfreaks.com/topic/154916-php-time-vs-mysql-now/#findComment-814835 Share on other sites More sharing options...
PFMaBiSmAd Posted April 20, 2009 Share Posted April 20, 2009 Depending on operating system and php version, time() also has a serious 1970 or 1901 limitation that makes it unusable for things like birthdays, historical events... Quote Link to comment https://forums.phpfreaks.com/topic/154916-php-time-vs-mysql-now/#findComment-814842 Share on other sites More sharing options...
Mchl Posted April 20, 2009 Share Posted April 20, 2009 The main difference is: time(), returns time of webserver, NOW() returns time on MySQL server. These are not necessarily same. Quote Link to comment https://forums.phpfreaks.com/topic/154916-php-time-vs-mysql-now/#findComment-814862 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.