Jump to content

Set date using english input


itrends

Recommended Posts

Hi there, great to have finally joined here, hopefully you will be able to help me out on a little thing I am stuck with.

I am currently working on a project. Please dont say "use drop downs" or "use a calendar" etc, there is a reason I need to be able to do the following:

I need it so that a user can come to a single text box and they will enter a date and time. For example they could enter "Next Thursday at 1pm" or they could put "thursday week 1pm" perhaps even "thursday 28th december 1pm" etc etc

Essentially I want to put together all the possible variations that someone could use to enter a date and time via english input.

How can i translate things like this into the normal date and time value to be used in a database and indeed in php etc.

They could also enter things like:
28/7/06 or 280706.

I will point out once again, that for testing this will be in a webpage, but the final use is not for a webpage and as such I need it to function in this way. It may not be possible to get every variation, but any help to grabbing as many as possible and converting them to the datetime format would be highly appreciated.

really looking forward to any help.

Regards,
David

P.s
please don't just point me to documention on datetime etc, I have read lots and cant work out much of it as I have not been working with php long, thus why I have come for help :)

Link to comment
Share on other sites

[code]<?php
//Let's say the input is stored at $input.

echo date("j.m.y H:i:s", strtotime($input));

?>[/code]

[url=http://www.php.net/manual/en/function.strtotime.php]strtotime()[/url] can prase almost every english input into a timestamp, which [url=http://www.php.net/manual/en/function.date.php]date()[/url] can handle :)

Orio.
Link to comment
Share on other sites

I dont think there is going to be a quick solution to this and there is going to be a lot of trial and error, especially as you want it to be able to accept inputs such as "next tuesday" etc.

I think to start with, perhaps explode() the entry into an array and work each element of the array individually to try and build up a recognisable date format. ie look for the obvious elements to start with that match with a 4 digit year entry, or match the name of a day or month.  You may have to go as far as working backwards, ie you know it is a Tuesday in January 2007, what dates could it be that fit?

Good luck, and I will try and come back with some ideas for scripting this.
Link to comment
Share on other sites

Sorry only just got back here. I am going to work up a list of "essential formats" later on. The plan then is when a user enters their time and date it will print it out and say "is this correct?" if not then it will email me so I can see how that particular person tried to enter their date and time and can look to include that format for future use. :)

But I will try and list a basic set of possible examples asap.

Thanks for all the replies so far :)
Link to comment
Share on other sites

That specific example gave me: "26.12.06 10:00:00". But that's because I have to set the timezone settings. It will work if you use it properly.
strtotime() is the best thing you will be able to use.

You can find [url=http://www.gnu.org/software/tar/manual/html_node/tar_109.html]here[/url] what strtotime() will prase.

Orio.
Link to comment
Share on other sites

if a TIME is NOT specified it will assume 09:00
if a DATE is NOT specified then it will assume TODAY

time format possibilities:

00am
00pm
00 am
00 pm
00:00
0:00pm
0:00 pm
0:00am
0:00 am


0 hours time
0 hours
in 0 hours
0 mins
in 0 mins
0 minutes
in 0 mintues
in half an hour
half an hour
in quater of an hour
quater of an hour
in three quaters of an hour
three quaters of an hour
every hour
every 0 mins
every 0mins
every 0minutes
every 0 minutes
every 0 hours
every 0hours


date format possiblities:

most of the below should be able to include "yearly" "every year" "next x years" "for x years" "daily" "every day" "next x days" "for x days" etc where appropriate to denote that it should happen every year, every month, or every day.

next tuesday
next week
next year
today
tomorrow
x days time
in x days
in x days time
00/00/00
0/00/00
00/00/0000
0/00/0000
28th (assumes 28th of this month)
28 january
28th of january

then months e.g. jan, feb, march etc

Thats all i can think of for now.
Link to comment
Share on other sites

At the moment I am unable to say what it is for, but it is not going to be in a situation where a strict format can be requested or ineed an example format easily displayed.

though this will be proccessed via php, its entry will not be via a computer directly, long story but exciting project ;)
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

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.