Navigate
Home
ArticleWiki
Forum
Journal
Search
Newsletter
Links
Tech News
expertsrt.com
Welcome Guest.
Username:

Password:

Remember me

Proper way to handle and store DATE in mysql
Welcome, Guest. Please login or register.
December 03, 2008, 03:43:38 PM
11305 Posts in 1249 Topics by 498 Members
Latest Member: katCheeme
Experts Round Table Network  |  Databases  |  MySQL  |  Proper way to handle and store DATE in mysql « previous next »
Pages: [1]
Author Topic: Proper way to handle and store DATE in mysql  (Read 436 times)
thepreacher

Offline Offline

Posts: 78


« on: April 13, 2007, 03:01:09 PM »

Say l have a date say 13 April 2007 (UK style). for the Month the actual value i am storing becomes 4 so the date is 13 4 2007. I rearrange it to yearmonthday format as that is how mysql stores dates. This date now becomes 2007413. When i store it, mysql stores it as 200-74-13. What is the right way to do this seeing that mysql uses 0000-00-00.

Secondly in the situation where i only need to store the month and year, ie 0000-00, how do i do this so that mysql will do the right thing. I use PHP BTW.
« Last Edit: April 13, 2007, 11:19:45 PM by thepreacher » Logged
VGR
Mentor

Offline Offline

Posts: 682



WWW
« Reply #1 on: April 15, 2007, 12:50:19 AM »

1) you forgot the leading zero for the month. Use a dat() format that pads zeroes to the left (I always use Y-m-d H:i:s)
2) just store your data appended with "-01" (a fake day) and ignore it when retrieving data
Logged

techie overlord, answers all kind of questions on http://www.europeanexperts.org
Pages: [1]
« previous next »
    Jump to: