Coding using SQL date_format
Moderator: General Moderators
Coding using SQL date_format
I have seen discussion in here about using the SQL date format for date output formatting. People say that it is best to have SQL do the date processing rather than PHP. I have talked to others that say that there are anomalies in the date_format parameters between different flavors of SQL (PostgreSql, MS-SQL, MySQL, etc...). If this is the case and you are trying to code a universal application using the PEAR DB or MDB2 abstraction layers that could be used on any of the supported databases, wouldn't this cause compatibility issues? Wouldn't the PHP date function be better in that case?
- jaoudestudios
- DevNet Resident
- Posts: 1483
- Joined: Wed Jun 18, 2008 8:32 am
- Location: Surrey
Re: Coding using SQL date_format
I use time() from php functions.
It generates a unix timestamp from 1970 in seconds. It is very easy to work with, add, subtract etc. Even within mysql it can do calculations i.e add 1 year.
$nextyear = mktime(0, 0, 0, date("m"), date("d"), date("Y")+1);
It generates a unix timestamp from 1970 in seconds. It is very easy to work with, add, subtract etc. Even within mysql it can do calculations i.e add 1 year.
$nextyear = mktime(0, 0, 0, date("m"), date("d"), date("Y")+1);