Solved

PHP Reversing order of MMYY

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

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

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…
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.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

777 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