Dates

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

Dates

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

Reply

FaLgoR
I don't know if is it what you want, but here we go smile.gif

If you want to add the full date in somewhere, you'll have to use the function date. In this case, I think you must use date("r");

CODE

<? echo date("r"); ?>


Put it wherever you want.

Reply

Newton
You could use strtotime function present in php. You might have to format your string accordingly though. I haven't really worked with the function much but if you use a format such as, "10 April 2005", it'll give you the timestamp. Just play around with it for a bit and see what you come up with.

Reply

Spectre
I'm not entirely sure what the form in question is for or exactly what fields exist, but it would probably be better to have three text fields - one for the month, the day, and the year (doesn't have to be in that order, obviously). Also remember to specify which is which. You could then parse the data knowing exactly how it should be formatted, and pass it to the mentioned strtotime() function.

Reply

beeseven
Strtotime is very versitile. As long as you have a word for the month, it'll work with most formatting. But if your users don't know this, it would be easiest, as was already said, to use multiple inputs. Especially if you use a drop down box where possible.

Reply

Mike
Are the people on your site posting things that makes them have to post the date of the their post. If so you could just add this to the post page:

CODE


$time = date();



And you would insert '$time' into the date field instead of what the user would type, like '{$_POST['date']}'. Then where you would fetch the dates from the database to show them to everyone else, you would put this code:

CODE


$query = mysql_query("SELECT date FROM db") or die(mysql_error());
$fetch = mysql_fetch_row($query);
$gotit = $fetch[0];
$date = date('m-d-y g:i:s',$gotit);




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.

Similar Topics

Keywords : dates

  1. Asking Girls Out On Dates
    (15)
  2. The Elder Scrolls Iv Oblivion
    Release Dates (official ship date released!) (8)
    so..... how's everyone doing? ok? that's good, glad to hear it. so, um..... WHEN THE
    HECK IS ELDER SCROLLS IV: OBLIVION COMING OUT?! *ahem* I heard it was march now. late
    march... so, whatever happened to DECEMBER 30TH!??!?!?!! I wouldn't mind
    the extra time if they were adding a mutiplayer or more maps, but no! apprently, they're
    just tweaking. all fine and good. it's hard to work with new technology (can't wait for
    radiant AI), but sheesh, it just keeps being pushed back everytime we get within a couple w....
  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. Gt4 Online?
    DATES PLEASE? (6)
    does anyone know if GT4 is going to have an online expansion, and if yes when? cuz grand tourismo is
    the best realistic racing game and it needs ONLINE! i bought it for online play, i stuck it in,
    and there wasnt any /ohmy.gif' border='0' style='vertical-align:middle' alt='ohmy.gif' /> i got
    pissed and threw it havnt played it for a while, im waiting on online pack. or update. please inform
    me?!....
  5. Converting Dates
    converting epoch to MM-DD-YYY (1)
    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!....
  6. For Latest Reviews And Release Dates On Everything
    www.flaminvibez.com (2)
    check out my new site that im finally done with. I still need to fix some stuff but its basically
    done. please check it out and gimme some feedback. also plz register at the forums /smile.gif'
    border='0' style='vertical-align:middle' alt='smile.gif' /> ....
  7. Dates For Psp?
    does anyone one the real date (1)
    is it ture that the PSP is out in the US on the 24/03/2005 and the uk have to wait till 24th june
    /sad.gif' border='0' style='vertical-align:middle' alt='sad.gif' /> if thats so am buyin one from
    US /biggrin.gif' border='0' style='vertical-align:middle' alt='biggrin.gif' /> can any help with
    the dates if you know a date by the way am in the UK so if you have a date for the UK that would
    be great cheers chris....

    1. Looking for dates

*RANDOM STUFF*





*SIMILAR VIDEOS*
Searching Video's for dates

*MORE FROM TRAP17.COM*
advertisement



Dates



 

 

 

 

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