I have a date string "20 November, 2013"
and a time string "9:30 AM"
I need to get certain info from this string.
$date = "20 November, 2013";
$time = "9:30 AM";
$str = $date." ".$time;
$dtime = strtotime($date);
$DAY = date("d",$dtime);
$MONTH = date("m",$dtime);
$ttime = strtotime($time);
$HOUR = date("h",$ttime);
$MIN = date("i",$ttime);
$MER = date("A", $ttime);
I'm trying to get $DAY
to == "20", $MONTH
to == "11", et cetera. When the values are hard-coded in like above, seems to work fine, but when I replace $date
and $time
with my $_GET
parameters it breaks and returns incorrect data.
The script is being called from ajax.
var param11 = document.getElementById('dpdate').value;
var param1 = encodeURIComponent(param11);
var param21 = document.getElementById('dptime').value;
var param2 = encodeURIComponent(param21);
var url = "https://www.nnnn.com/picker/timeajax.php?time="+param1+"&date="+param2;
xmlhttpp.open("GET",url,false);
xmlhttpp.send(null);
Is there an easier way to do this? Or a way to fix what I'm currently doin?
You could use Moment.js library for parsing, validating, manipulating, and formatting dates. I used it couple of times and was really happy with the results.