views:

274

answers:

3

Hi,

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

+4  A: 

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

Sinan
+1  A: 

Though I vote for datejs.com, another option is timeapi.org.

timeapi.org has a JSONP API for converting natural language queries to date/time.

vsr
A: 

Thanks Sinan and vsr. I voted up for both your answers. I was initially very excited with what datejs has to offer, but it seems limited in its ability to process natural language date time. It doesn't handle date + time very well.

timeapi.org looks promising, but as it utilises ruby, and the api version relies on a service that does not appear to be very reliable.

I tested with php's strtotime and found that it could process more natural language date time pretty well. Using php allows me to add other natural language terms not supported too. So it looks like I'll be adopting ajax to process the natural language date time from the user.

Would love to hear your insights about my approach. :) thanks again!

Lyon