Welcome Guest ( Log In | Register)



 
Reply to this topicStart new topic
> Dates
fsoftball
post Apr 26 2005, 03:17 AM
Post #1


Member [Level 2]
*****

Group: Members
Posts: 78
Joined: 25-April 05
Member No.: 6,158



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.
Go to the top of the page
 
+Quote Post
FaLgoR
post Apr 26 2005, 04:41 PM
Post #2


Super Member
*********

Group: Members
Posts: 217
Joined: 2-January 05
Member No.: 3,084



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.
Go to the top of the page
 
+Quote Post
Newton
post Apr 29 2005, 11:19 AM
Post #3


Newbie [Level 1]
*

Group: Members
Posts: 11
Joined: 19-April 05
Member No.: 5,902



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.
Go to the top of the page
 
+Quote Post
Spectre
post May 24 2005, 03:08 AM
Post #4


Privileged Member
*********

Group: Members
Posts: 874
Joined: 30-July 04
Member No.: 246



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.
Go to the top of the page
 
+Quote Post
beeseven
post May 25 2005, 12:55 AM
Post #5


Privileged Member
*********

Group: Members
Posts: 629
Joined: 26-February 05
Member No.: 3,995



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.
Go to the top of the page
 
+Quote Post
Mike
post May 25 2005, 10:47 AM
Post #6


Owner of Sub-Zero
********

Group: Members
Posts: 159
Joined: 17-November 04
Member No.: 2,325



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);



Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic

Collapse

> Similar Topics

Topics Topics


 



- Lo-Fi Version Time is now: 5th September 2008 - 06:29 AM