Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

PHP Reversing order of MMYY

Posted on 2011-09-14
3
Medium Priority
?
301 Views
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
0812
0208

How do I fill only if it comes back as 8 rather than 08?
0
Comment
Question by:kkbenj
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 4

Accepted Solution

by:
h4hardy earned 2000 total points
ID: 36535265
you are near to solution..here 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

0
 

Author Closing Comment

by:kkbenj
ID: 36535293
Thanks, I was overthinking it.
0
 
LVL 4

Expert Comment

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

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
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 …
Suggested Courses

604 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