Pages

Welcome to My Blog

This is to share my IT experience with friends all around the world.
I have been working in Linux Fedora Systems for more than 8 years. Its fun to share knowledge and learn..
As everyone knows when a problem arises in your systems "googling" is the way that many depend on..

All the posts here are my working experiences during my working life.. So you can count on it..

I have added the references where I got help in solving IT issues


Monday, June 20, 2011

MySQL DATE_SUB Function

If you are using a database as the back-end, programmers needs to access data from the databases (i.e. MySQL) and process them before display information to the clients. For example if you have date of Birth (dob) in a database table column, you need to read each dob from the table and calculate the age inside your coding.
If you are using MySQL, it allows you to do small calculations with your queries.

DATE_SUB / DATE_ADD are very useful MySQL functions which reduce more coding in your program.

Following given is one example of using DATE_SUB function.

$query = "select customer.name as name, orig_date from where orig_date > DATE_SUB(CURDATE(),INTERVAL 7 DAY)
This will display the records created within one week time

Good Reference
http://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html

No comments:

Post a Comment