Solved

PHP Reversing order of MMYY

Posted on 2011-09-14
3
250 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
  • 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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

This article will explain how to display the first page of your Microsoft Word documents (e.g. .doc, .docx, etc...) as images in a web page programatically. I have scoured the web on a way to do this unsuccessfully. The goal is to produce something …
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

707 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

12 Experts available now in Live!

Get 1:1 Help Now