I need to pass a date time (in 2012-09-23 21:00:00 format generated by dropdown boxes and converted to that format with javascript (client side that is)) with GET method to a php file which then gets mysql records sorted by that time.
What is the best way of passing this date? The options I consider are:
- making separate get parameters for each piece of info (e.g ?startYear=2012&startMonth=09&startDay=23&startHour=....) this could work, but what if I add more different filters. It will be too busy there. Or it's not an issue?
- Passing timestamp. I consider this to be the best option. However when I convert the date to timestamp it gives me incorrect result. The function will be below.
- Passing in 2012-09-23 21:00:00 format by pre-processing with encodeURIComponent
Any suggestions?
Date to timestamp conversion (related to point 2):
function getTimestamp(str) {
var d = str.match(/\d+/g); // extract date parts
return +new Date(d[0], d[1] - 1, d[2], d[3], d[4], d[5]); // build Date object
}