I have an application I'm building with CodeIgniter. I have records in a SQL Server DB which have datetime fields.
I'm querying these records from dates entered into a textfield in the m/d/Y. This corresponds to the date format in the db.
Unfortunately I'm in the UK! So I want to enter dates in like d/m/Y. So I need to capture this, format it into the appropriate format and then validate it.
Here's the code in using to format:
$datestring = "%m/%d/%Y";
if(isset ($_POST['from_date']) AND isset ($_POST['to_date'])){
$from = mdate($datestring, strtotime($_POST['from_date']));
$to = mdate($datestring, strtotime($_POST['to_date']));
I'm using mdate from the CI date helper but it's pretty much the same as date() I think.
If I enter the data 13/12/2010 then post the form and dump the new date it comes out as
string(10) "02/06/2011"
How'd this happen?
Can someone lend a hand? :D
Billy
What I would do is explode the date by '/' and make a new date with mktime:
The answer is that the European date format uses dashes, not slashes.
According to the manual:
Using a correct format works like a charm: