Link to home
Start Free TrialLog in
Avatar of peter-cooper
peter-cooper

asked on

Convert date to dd/mm/yyyy

Hello
I am struggling to convert a date that I use as part of a filename of a zip file. At the moment it prints
bootstrap_21-Jun-2017-16-04-09-PM.zip
but I need to have it print
bootstrap_21/06/2017 16-04-09-PM.zip

I have posted the code I am using and would be grateful if someone could help with this. Thanks

$dateformat='d-M-Y-H-i-s-A';

case 'backupfile':
    echo    $_POST['db'].'_'.date($dateformat, time());					
break;

Open in new window

Avatar of Dave Baldwin
Dave Baldwin
Flag of United States of America image

You can't use '/' as part of a filename in Windows, Linux, or Mac OSX operating systems.
Have you tried this?
$dateformat='d/m/Y H-i-s-A';

Open in new window

Oh, yes, Dave is right, not as a filename!
ASKER CERTIFIED SOLUTION
Avatar of Dave Baldwin
Dave Baldwin
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
>> but I need to have it print bootstrap_21/06/2017 16-04-09-PM.zip
If you mean that you want that printed/echoes on the browser try using:
$dateformat='d/M/Y H-i-s-A';

Open in new window


If you meant that you want that as the actual filename then it won't work because there are some characters that are not allowed in filenames and the "/" is one of them.
Avatar of peter-cooper
peter-cooper

ASKER

Thanks very much dave. I learnt something new today.
YOu're welcome, glad to help.
You may want to learn about the ISO-8601 standard for date formats.  If you use that, you'll never go wrong!