Converting Dates - converting epoch to MM-DD-YYY

free web hosting
Open Discussion > CONTRIBUTE > Computers > Programming Languages > PHP Programming

Converting Dates - converting epoch to MM-DD-YYY

fsoftball
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!

Reply

lava.alt
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 format

YYYYMMDD

so 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 -> 20050201

and the same is for the months of the same year ...

february 1, 2005 -> 20050201(minor)
march 1, 2005 -> 20050301

and the same for the days

february 1, 2005 -> 20050201(minor)
february 4, 2005 -> 20050204

so when you make a query to your DB like this

SELECT YourDate, YourData
FROM YourTable
ORDER BY YourDate

the result will be this

20040101
20040201
20040231
20050101 ... and so on

and 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

ph34r.gif

 

 

 


Reply



Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

(Maximum characters: 10,000)
You have characters left.

Recent Queries:-
  1. date php mm/dd/yyy - 118.85 hr back. (1)
Similar Topics

Keywords : converting dates converting epoch mm dd yyy

  1. Converting Textarea Return Characters To <br /> - (9)
  2. Converting Characters In A Variable To Individual Values In An Array - turning variables into arrays (2)
    Say I have a variable such as $nav_item and it had to contents Home . IE: CODE
    $nav_item = 'Home'; How would I make so that $nav_item was an array and
    had the following contents? CODE $nav_item = array ('h', 'o',
    'm', 'e'); With the case changing (ie H would become h and U
    would become u ) EDIT: Okay found out that I could change the case with
    array_change_key_case ($nav_item, CASE_LOWER); ...
  3. Drop Down Lists Using Dates - (5)
    Hi, I have a page where the user enters a date. I would like to use drop down boxes for the date.
    I would like the current date to be the default date. I think that part is pretty easy. However,
    I am having trouble listing all of the months. It wills tart at July and end at December. I need
    to list January through June. Anyone know a good way to list all the months? I am assuming that
    I will be able to do the same sort of thing for the date. Thanks!...
  4. Dates - (5)
    Hi, i have users entering a date as a text field. it is simply in ther form: "Apr 4". since it is
    text, i cannot sort and the dates end up out of order. i am guessing that the best way to sort is
    to conveert it to an epoch and sort on that. is there a function to convert this text into a epoch
    date? thanks....



Looking for converting, dates, converting, epoch, mm, dd, yyy

*RANDOM STUFF*





*SIMILAR VIDEOS*
Searching Video's for converting, dates, converting, epoch, mm, dd, yyy

*MORE FROM TRAP17.COM*
advertisement



Converting Dates - converting epoch to MM-DD-YYY



 

 

 

 

ADD REPLY / Got an Opinion! a humble request :-) RAPID SEARCH! Free Hosting [X]
Express your Opinions, Thoughts or Contribute your information that might help someone here.
Ask your Doubts & Queries to get answers.. "Together, We enlight each other!"
Register FREE for AD-FREE forum, Create your own topics, Ask Questions, track topics, setup subscriptions & notifications and Get a Free Website w/ Email and FTP.
500MB Space *No Ads*, CPanel, FTP, PHP, MySQL, EMails - 100% FREE