Page 1 of 1

Date/Time Calculations: Inline Script or Database?

Posted: Thu Oct 09, 2003 2:32 pm
by voodoo9055
I am currently working on a project that will have a heavy load of date/time calculations in it. PHP and MySQL have a few similar functions, but MySQL seems to have even more functions overall.

In terms of speed, is it better to perform your data calculations with your SQL commands or do you feel it is better to use your script to perform your calculations?

Posted: Thu Oct 09, 2003 2:47 pm
by JAM
Really, really depends...

I'd guess MySql directly. Have in mind that if you can do everything on the database without using PHP, you do not need to query it, hence you dont need to use resources on the actual data-transport between db-php-db.

Make two scripts. Both producing a similiar result as in the final script. One in PHP and the other in the db. Loop it and take the time using microtime() or similiar.

Posted: Thu Oct 09, 2003 5:22 pm
by voodoo9055

Have in mind that if you can do everything on the database without using PHP, you do not need to query it,
How do you use a database function without using a query?

Posted: Thu Oct 09, 2003 7:13 pm
by McGruff
What kind of date/time calculations?

If you require sets of data filtered by date expressions, definitely do that with query logic (and of course a good database design).

Formatting date/time info on the other hand could be regarded as more of a presentation (ie php) task.

Posted: Thu Oct 09, 2003 7:49 pm
by voodoo9055
From my project's prospective, I am will need a calculation to come up with the number of days, hours, minutes, and seconds between two dates. I been playing around with this and it looks like I have no choice but to use a combination of the two (script and database).