PHP Reversing order of MMYY

Posted on 2011-09-14
Last Modified: 2012-05-12
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

How do I fill only if it comes back as 8 rather than 08?
Question by:kkbenj
  • 2

Accepted Solution

h4hardy earned 500 total points
ID: 36535265
you are near to is the code

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

Open in new window


Author Closing Comment

ID: 36535293
Thanks, I was overthinking it.

Expert Comment

ID: 36535320
yes.... a great coder do a silly mistake always...!

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now