itrends Posted December 20, 2006 Share Posted December 20, 2006 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 etcEssentially 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,DavidP.splease 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 :) Quote Link to comment Share on other sites More sharing options...
Orio Posted December 20, 2006 Share Posted December 20, 2006 [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. Quote Link to comment Share on other sites More sharing options...
chiprivers Posted December 20, 2006 Share Posted December 20, 2006 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. Quote Link to comment Share on other sites More sharing options...
chiprivers Posted December 20, 2006 Share Posted December 20, 2006 Could you give a fuller list of the possible inputs that you want to be able to work with? Quote Link to comment Share on other sites More sharing options...
Orio Posted December 20, 2006 Share Posted December 20, 2006 @chiprivers- Have you read my post?Orio. Quote Link to comment Share on other sites More sharing options...
itrends Posted December 20, 2006 Author Share Posted December 20, 2006 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 :) Quote Link to comment Share on other sites More sharing options...
chiprivers Posted December 20, 2006 Share Posted December 20, 2006 [quote author=Orio link=topic=119395.msg488927#msg488927 date=1166628197]@chiprivers- Have you read my post?Orio.[/quote]Will your suggestion parse entries such as next tuesday at 1pm? Quote Link to comment Share on other sites More sharing options...
Orio Posted December 20, 2006 Share Posted December 20, 2006 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. Quote Link to comment Share on other sites More sharing options...
itrends Posted December 20, 2006 Author Share Posted December 20, 2006 if a TIME is NOT specified it will assume 09:00if a DATE is NOT specified then it will assume TODAYtime format possibilities:00am00pm00 am00 pm00:000:00pm0:00 pm0:00am0:00 am0 hours time0 hoursin 0 hours0 minsin 0 mins0 minutesin 0 mintuesin half an hourhalf an hourin quater of an hourquater of an hourin three quaters of an hourthree quaters of an hourevery hourevery 0 minsevery 0minsevery 0minutesevery 0 minutesevery 0 hoursevery 0hoursdate 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 tuesdaynext week next yeartodaytomorrowx days timein x daysin x days time00/00/000/00/0000/00/00000/00/000028th (assumes 28th of this month)28 january28th of januarythen months e.g. jan, feb, march etcThats all i can think of for now. Quote Link to comment Share on other sites More sharing options...
itrends Posted December 20, 2006 Author Share Posted December 20, 2006 Ahhh so there are bits like this:http://www.gnu.org/software/tar/manual/html_node/tar_115.html#SEC115hmmmm Quote Link to comment Share on other sites More sharing options...
chiprivers Posted December 20, 2006 Share Posted December 20, 2006 If you don't min dme asking, what is this going to be used for? Surely it would be easier to just ensure that the date was input in a strict format? Quote Link to comment Share on other sites More sharing options...
itrends Posted December 20, 2006 Author Share Posted December 20, 2006 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 ;) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.