I’m using the jquery calendar picker to get my users to enter dates in the form “dd/mm/yyyy”. I’d like to use php to convert this into a timestamp that I’ll upload to my database. I’m not quite sure what syntax of strtotime that I use so that php knows that my date is in the form above as opposed to, say, the European version mm/dd/yyyy. Any help would be appreciated.
[ot]dd/mm/yyyy is the European format, while mm/dd/yyyy is the American format (us Americans are weird in that we don’t follow the usual endian order of values with dates).
Thanks for the reply! I fear that I’m a bit more versed in PHP at this stage of the game and I’m using PHP to write the date to my database; so it would be much easier if there’s a PHP based solution to convert dd/mm/yyyy from my textfield into a timestamp.
You can’t use strtotime() directly with a dd/mm/yyyy formatted date as it expects that pattern of numbers to (incorrectly for your needs) be mm/dd/yyyy (see date formats). There are a couple of options, including a) using a method specifically designed for getting a date from a specified date format, or b) manipulating the date you have into one that strtotime() will like.
However the above is only available with PHP 5.3, so if you aren’t using something that recent (why not?!), an alternative is to use some string manipulation to coerce the date into the format that suits you.
You would just be over-complicating things unnecessarily. If the datepicker sends the format you’re looking for, no conversion would be necessary. Complicated = error-prone.
Go ahead and post the code for the datepicker. All that needs to be added is the dateFormat option.