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.

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

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

// Outputs  20120107T162000Z


Check it out in action:


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
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);
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);
$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.



Karl DeSaulniers
Design Drumm

Jim Lucas


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

Reply via email to