Jul 26, 2008

Dates

Free Web Hosting, No Ads > CONTRIBUTE > Computers > Programming Languages > PHP Programming

free web hosting

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.
Confirm Code:

Similar Topics

Keywords : dates

  1. Drop Down Lists Using Dates - (5)
  2. 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!...



Looking for dates

Searching Video's for dates
advertisement



Dates



 

 

 

 

ADD REPLY / Got an Opinion! Remove these ADs! RAPID SEARCH! Free Web Hosting [X]
Express your Opinions, Thoughts or Contribute more info. to help others.
Ask your Doubts & Queries to get answers, So that "Together We can help others!"
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