I have a form requiring date in dd/mm/yyyy
format
and I've tried to convert it to a timestamp with strtotime()
function
but I've seen it works only if you fill the form with date written like dd-mm-yyyy
how could i solve? I don't know abroad but here in Italy nobody writes dates like that dd-mm-yyyy
Why not use str_replace?
Or better yet, convert the string into
YYYY-MM-DD
before you insert.Stop using
strotime()
,date()
,time()
etc. functions, start using DateTime.Perfect solution for all types of known input :
And why do you need timestamp for?
Why explode, replace or even cut string??? Just use createFromFormat.
There is v5.5 already out. I think answers should be for the latest code, not for code from the year 2006. Yes v5.2 was released in 2006 and v5.3 in 2009 (see release dates). If OP requests old code, find it on SO, and close this question with duplicate; don't answer it.
Learn it.
Show me one thing that this functions can do, and DateTime cannot.
"Deprecated" code examples :
If you have another example of deprecated code, edit this answer and add it ;)
Quite lengthy.
Your question is not very clear.
If you receive from a form the date in format "dd/mm/yyyy" and you need to convert it in "yyyy-mm-dd" you can simply use substr:
and