Storing date as m/Y

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
aceconcepts
DevNet Resident
Posts: 1424
Joined: Mon Feb 06, 2006 11:26 am
Location: London

Storing date as m/Y

Post by aceconcepts »

Hi,

I have a field titled startDate of data type DATE and has an input mask of 0000-00-00.

What I would like to do is store a date as mm/yyyy (08/2007).

How can I do this?
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

You'd just... do it. There's not much reason to, though. You could always store it as YYYY-MM-DD and display it as mm/yyyy. If you store it as mm/yyyy, you'll have problems with ordering.
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Post by onion2k »

For things like credit card expiry dates where there's only a month and year I store them as a date field, but always insert them as the first of the month the user entered. For example, if the user updates their card to expire on 08/2010 it goes into the database as 2010-08-01. It's not ideal, but it works.
User avatar
aceconcepts
DevNet Resident
Posts: 1424
Joined: Mon Feb 06, 2006 11:26 am
Location: London

Post by aceconcepts »

Hi onion2k,

Yeah thats what I ended up doing with the date.

Thanks for your posts.
Post Reply