Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Parsing natural language date/time values into formatted date/time strings

I'm trying to let users type in date and time values into an input field. Some examples may include:

Tomorrow at 3pm
Now
Today at 1pm
Next tuesday 4pm

How would I go about parsing such readable text into date/time strings?

E.g. dd/mm/yyyy hh:mm

Can it be done client-side using jquery or must it be done ajax through php?

Thanks in advance for any advice or insights :)

like image 980
Lyon Avatar asked Mar 02 '10 13:03

Lyon


People also ask

What is parse date time?

The Date. parse() method parses a string representation of a date, and returns the number of milliseconds since January 1, 1970, 00:00:00 UTC or NaN if the string is unrecognized or, in some cases, contains illegal date values (e.g. 2015-02-31). Only the ISO 8601 format ( YYYY-MM-DDTHH:mm:ss.

How do I convert a string to a date?

Using strptime() , date and time in string format can be converted to datetime type. The first parameter is the string and the second is the date time format specifier. One advantage of converting to date format is one can select the month or date or time individually.


1 Answers

There is an open source javascript library doing all that funky stuff with dates. You can check out http://www.datejs.com/

like image 180
Sinan Avatar answered Oct 14 '22 05:10

Sinan