Re: Converting date string to unix timestamp

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]


Never mind, it's because January 1st is not a Saturday.
The 7th is.

Interesting... so it corrects the date per the text representation of the day??

Thanks again.

Best,
Karl



On May 11, 2012, at 7:42 PM, Jim Lucas wrote:

On 05/11/2012 04:11 PM, Karl DeSaulniers wrote:
Hello everyone,
Got a quick one (I hope), and probably an easy one.
For some reason it is eluding me at the moment.
Hoping someone can help.

I am building an ics file with PHP and the form that is submitting to
create this ics file has a jQuery date picker on it.
The date furnished comes to me like this "Saturday, January 1, 2012",
and a time furnished like "4:20 pm" with no seconds.

Now for the ics file, I need the date/time combo to be..

Ymd\THis\Z or in the case of the above date and time, 20120101T042000Z

Here is the block of code that I am using for this.


Why do you have so much code to do such a simple thing?

This works for me.

<?php
$date = "Saturday, January 1, 2012";
$time = "4:20 pm";

echo date('Ymd\THis\Z', strtotime($date.' '.$time));

// Outputs  20120107T162000Z

?>

Check it out in action:
http://www.cmsws.com/examples/php/jquery_time_stamp.php
http://www.cmsws.com/examples/php/jquery_time_stamp.phps

Jim

CODE [
...
}
else {
$dt_start = $_POST["field20"] ? $_POST["field20"] : $_POST["field21"];
//Saturday, January 1, 2012
$dt_end = $_POST["field22"]; //Saturday, January 1, 2012
$t_start = $_POST["field24"]; //4:20 pm
$t_end = $_POST["field25"]; //5:55 pm
//date_default_timezone_set('UTC');
try {
$start_DT = new DateTime($dt_start . " " . $t_start);
$st_date_fmt = new DateTime($start_DT->format("l, F d, Y\TH:ia T"));
//$startdate_stamp = strtotime($st_date_fmt);
$startdate = $st_date_fmt->format('U');
//$startdate = date('Ymd\THis\Z', $startdate_stamp);
}
catch (Exception $e) {
trigger_error("startdate error: " . $e->getMessage(), E_USER_ERROR);
exit(1);
}
try {
if(empty($dt_end)) {
$enddate = $startdate + (60 * 60); //If no end date provided, enddate is
1 hour after startdate.
} else {
$end_DT = new DateTime($dt_end . " " . $t_end);
$end_date_fmt = new DateTime($end_DT->format("l, F d, Y\TH:ia T"));
//$enddate_stamp = strtotime($end_date_fmt);
$enddate = $end_date_fmt->format('U');
//$enddate = date('Ymd\THis\Z', $enddate_stamp);
}
}
catch (Exception $e) {
trigger_error("enddate error: " . $e->getMessage(), E_USER_ERROR);
exit(1);
}
$stampnow = date('Ymd\THis\Z', time());
//$datestampnow = strtotime($stampnow);
}
...
]

I have a feeling I am mixing something up on my own, but I have been
staring at this code to long to see it.
Can anyone help me please? Like I said, this is probably an easy one.

TIA!!

Best,

Karl DeSaulniers
Design Drumm
http://designdrumm.com




--
Jim Lucas

http://www.cmsws.com/
http://www.cmsws.com/examples/
http://www.bendsource.com/

Karl DeSaulniers
Design Drumm
http://designdrumm.com


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [Find Someone]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux