Re: [PHP] comparing time (related question)
On Wednesday, April 24, 2002, at 11:37 AM, Jackson Miller wrote: > When storing dates and times in databases is it better to store them as > UNIX timestamps or in one of the SQL date/time types? > > I am working on an application that takes school attendance and has > homework assignments, so I am doing a fair amount of date work. > Currently I am storing everything as date time and referring to a day > with the UNIX timestamp for midnight of that day. I am able to do > everything I need to do with both formats, but I am wondering if there > is a performance issue at hand. As I recently discovered, it is much better to store them as a SQL date/time type, because your database will be better equipped to make complicated queries of the data if it is stored in the database's preferred data type. The flexibility of functions such as MySQL's DATE_FORMAT() or UNIX_TIMESTAMP() functions, and PHP's date() function, let you manipulate these numbers in any way you prefer for display, once the database has performed its work. Erik Erik Price Web Developer Temp Media Lab, H.H. Brown [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] comparing time (related question)
I think Miguel said it all: I will just add you this reference on mySQL (if that's what you use) field types reference. http://mysql.com/doc/D/a/Date_and_time_functions.html As of performance I'd say: The logic should be: Store all the data in DB so when you retrieve it you can do every comparison right within SQL having so raw data for PHP to layout on your pages. That is the first rule of dynamicity, and RDBMS (even if mySQL is kind of not...) usually count on such uses. Sincerely, Maxim Maletsky Founder, Chief Developer www.PHPBeginner.com // where PHP Begins -Original Message- From: Miguel Cruz [mailto:[EMAIL PROTECTED]] Sent: Wednesday, April 24, 2002 6:20 PM To: Jackson Miller Cc: [EMAIL PROTECTED] Subject: Re: [PHP] comparing time (related question) On 24 Apr 2002, Jackson Miller wrote: > When storing dates and times in databases is it better to store them > as UNIX timestamps or in one of the SQL date/time types? > > I am working on an application that takes school attendance and has > homework assignments, so I am doing a fair amount of date work. > Currently I am storing everything as date time and referring to a day > with the UNIX timestamp for midnight of that day. I am able to do > everything I need to do with both formats, but I am wondering if there > is a performance issue at hand. If you want to use your database's time functions for comparison or grouping when selecting data, then it usually makes sense to use the database's native time format. Easy enough to convert back and forth (it's usually cheaper to have the database convert to unix timestamps and to have PHP convert in the other direction, from timestamps to database format). miguel -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] comparing time (related question)
On 24 Apr 2002, Jackson Miller wrote: > When storing dates and times in databases is it better to store them as > UNIX timestamps or in one of the SQL date/time types? > > I am working on an application that takes school attendance and has > homework assignments, so I am doing a fair amount of date work. > Currently I am storing everything as date time and referring to a day > with the UNIX timestamp for midnight of that day. I am able to do > everything I need to do with both formats, but I am wondering if there > is a performance issue at hand. If you want to use your database's time functions for comparison or grouping when selecting data, then it usually makes sense to use the database's native time format. Easy enough to convert back and forth (it's usually cheaper to have the database convert to unix timestamps and to have PHP convert in the other direction, from timestamps to database format). miguel -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] comparing time (related question)
When storing dates and times in databases is it better to store them as UNIX timestamps or in one of the SQL date/time types? I am working on an application that takes school attendance and has homework assignments, so I am doing a fair amount of date work. Currently I am storing everything as date time and referring to a day with the UNIX timestamp for midnight of that day. I am able to do everything I need to do with both formats, but I am wondering if there is a performance issue at hand. Thanks for any replies. -Jackson -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] comparing time
On Wed, 24 Apr 2002, Cosmin wrote: > How can I compare time? So I have to check a difference of 12 or 24 hours > this mean I have to compare the time between the days too.. > > How I can make this comparing > just comparing hour with hou and then minute with minute or is possible > all of them at the same time? As long as you don't care about any units larger than days (months and years are variable-length and thus a little more work), you can just calculate the difference between two unix timestamps. They're just an integer number of seconds. Subtract the two, divide by 60 for minutes, 3600 for hours, or 86400 for days. miguel -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] comparing time
At 24.04.2002 11:05, you wrote: >Hello, > >How can I compare time? So I have to check a difference of 12 or 24 hours >this mean I have to compare the time between the days too.. > >How I can make this comparing >just comparing hour with hou and then minute with minute or is possible >all of them at the same time? use mktime() to convert your dates in Unix-imestamps, then you can do whatever you like to make them "human" readable used date(). Oliver -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] comparing time
Hello, How can I compare time? So I have to check a difference of 12 or 24 hours this mean I have to compare the time between the days too.. How I can make this comparing just comparing hour with hou and then minute with minute or is possible all of them at the same time? Thanks Cosmin -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php