tags:

views:

24

answers:

3

Taking user input such as "tomorrow", "in three days", "3 months 30 days", "march 30, 2011" and interpreting it into a timestamp usable by php.

I feel like I've seen something like this before in a task management system. I'd like to use it for something a little different but I can't find anything precooked anywhere. Maybe I saw it on Remember the Milk? (It's down as I'm writing this)

Does anyone know of something like this? (preferably php)

+1  A: 

One of the best implementation I have seen is this javascript. It does what you are looking for, but on the client side! It is not php, but since it is client side, the usage of it should fit your need quite well!

code-zoop
i like this. i may use this alongside of strtotime! thanks
Luke Burns
+1  A: 

Function strtotime() will parse many of 'natural language' time expressions. http://www.php.net/manual/en/function.strtotime.php

Also DateTime class uses same parser, but it can hold wider range of dates http://www.php.net/manual/en/book.datetime.php

Mchl
+1  A: 

Take a look at strtotime:

<?php
$now = time();
printf("%20s : %s\n", 'now', date('Y-m-d H:i:s', $now));

foreach( array("tomorrow", "+ 3 days","3 months 30 days","march 30, 2011") as $userinput ) {
  $ts = strtotime($userinput, $now);
  printf("%20s : %s\n", $userinput, date('Y-m-d H:i:s', $ts));
}

prints

             now : 2010-08-08 09:44:49
        tomorrow : 2010-08-09 00:00:00
        + 3 days : 2010-08-11 09:44:49
3 months 30 days : 2010-12-08 09:44:49
  march 30, 2011 : 2011-03-30 00:00:00
VolkerK
thank you. this is good.
Luke Burns