Jump to content
xisto Community
Sign in to follow this  
fsoftball

Converting Dates converting epoch to MM-DD-YYY

Recommended Posts

So this is probably a basic and lame question, but how can I convert dates so I can then sort them? Right now, I have each part of a date as a separate variable: $month, $day, $year. I'd like to store them in the database as epoch. This way when I do a query I can sort them by date. I can figure out the datatype for the database later.I would also need to convert an epoch to Month-Day-Year later on when I want to display this.I'm sure this isn't too complicated but I figured asking for some suggestions anyway.Thanks!

Share this post


Link to post
Share on other sites

well i have expirience working with dates ... the way i sugget you to mange the date is the next ... work with them as Long variables .... with the next formatYYYYMMDDso when you try to sort them, as they are numbers, for example a date of the year 2004 will always be minor of a date of 2005 with that base ... ex.february 1, 2004 -> 20040201 (minor)february 1, 2005 -> 20050201and the same is for the months of the same year ...february 1, 2005 -> 20050201(minor)march 1, 2005 -> 20050301and the same for the daysfebruary 1, 2005 -> 20050201(minor)february 4, 2005 -> 20050204so when you make a query to your DB like thisSELECT YourDate, YourDataFROM YourTableORDER BY YourDatethe result will be this20040101200402012004023120050101 ... and so onand when you show the date to the user yo only give to it a format as you want it dd/mm/yyyy or mm/dd/yy .. as you wish :rolleyes:

Share this post


Link to post
Share on other sites
Guest
This topic is now closed to further replies.
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.