Solved

PHP Reversing order of MMYY

Posted on 2011-09-14
3
281 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 500 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
This article discusses four methods for overlaying images in a container on a web page
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to count occurrences of each item in an array.

740 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