Date/Time Calculations: Inline Script or Database?

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

Post Reply
User avatar
voodoo9055
Forum Commoner
Posts: 51
Joined: Sat Apr 26, 2003 3:27 pm
Location: Montgomery, AL

Date/Time Calculations: Inline Script or Database?

Post 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?
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Post 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.
User avatar
voodoo9055
Forum Commoner
Posts: 51
Joined: Sat Apr 26, 2003 3:27 pm
Location: Montgomery, AL

Post 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?
McGruff
DevNet Master
Posts: 2893
Joined: Thu Jan 30, 2003 8:26 pm
Location: Glasgow, Scotland

Post 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.
User avatar
voodoo9055
Forum Commoner
Posts: 51
Joined: Sat Apr 26, 2003 3:27 pm
Location: Montgomery, AL

Post 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).
Post Reply