Link to home
Start Free TrialLog in
Avatar of kkbenj
kkbenj

asked on

PHP Reversing order of MMYY

If I have user input of 0812, I need the variable to be changed to 1208.  So my quick attempt to do this is:

$expiry_date=$_POST[abc]; //'1308' YYMM
$backwardsExpiry = sprintf("%02d",substr($_POST[abc],3,2)).sprintf("%02d",substr($_POST[abc],0,2));
print("Expiry = " . $expiry_date."<br>");
print("Backwards = " . $backwardsExpiry."<br>");

The print out is
0812
0208

How do I fill only if it comes back as 8 rather than 08?
ASKER CERTIFIED SOLUTION
Avatar of h4hardy
h4hardy
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
Avatar of kkbenj
kkbenj

ASKER

Thanks, I was overthinking it.
yes.... a great coder do a silly mistake always...!