Re: [PHP] A relative date puzzle

[email protected] (Mattias Thorslund)
Newsgroups php.general
Message-ID <[email protected]>
On 4/1/13 11:05 AM, Jim Giner wrote:
> I'm looking for some ideas on how to handle the following get a 
> datetime value that is relative to a specific future date when 
> presented with a partial day &time value.
>
> Specifically, I have an appl that requires some lengthy input 
> involving days and times.  I have streamlined the d/e effort so that 
> it can be done entirely using the number keypad (if available), or 
> else just with numeric entries.  Works great, very quick (JS) and 
> accurate.  Basically the users type some numbers and end up with 
> something like:
>
> Sat 08:00am  or Fri 07:00pm etc.
>
> Does anyone have an idea on how I can convert this value to a true 
> datetime value for my database updates, where the above value is 
> relative to a specific date in the future?  IE, the d/e takes place a 
> few days before a certain upcoming date and I want my entry of "Sat" 
> to translate to the Saturday following that certain date.  This could 
> take place one to two weeks prior to the start date, so just adding 
> "next" to the value above won't work.  I really need to incorporate a 
> specific date in the solution.
>
> Thoughts anyone?
>


Use strtotime() to get a UNIX time stamp, then use date() to format it 
as you like.

$myDate = strtotime("wed 11:00 am"); //1365012000
echo date("Y-m-d H:i:s", $myDate); //2013-04-03 11:00:00

On two lines for clarity.

Cheers,

Mattias
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.