Jump to content
xisto Community
Sign in to follow this  
fsoftball

Dates

Recommended Posts

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.

Share this post


Link to post
Share on other sites

I don't know if is it what you want, but here we go :lol:

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

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

Put it wherever you want.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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:

$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:

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

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
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.