Function ConvertExpiryDateToYYMMDD
The following is based on the code I wrote for version 1.5...
function ConvertExpiryDateToYYMMDD($theDate) {
// prepare to convert expiry date to yymmdd format
// handle dd/mm/yy dates including single digits for dd, mm, yy
// - e.g. 06/06/03, 6/6/03, 06/6/03, 6/06/03, 06/06/3 etc.
$position_of_first_slash = strpos($theDate, "/");
$expiry_day = substr($theDate, 0, $position_of_first_slash);
$expiry_mm_yy = substr($theDate, $position_of_first_slash + 1,
strlen($theDate));
$position_of_second_slash = strpos($expiry_mm_yy, "/");
$expiry_month = substr($expiry_mm_yy, 0, $position_of_second_slash);
$expiry_year = substr($expiry_mm_yy, $position_of_second_slash + 1,
strlen($theDate));
// if any of dd, mm or yy are single digits then add a leading zero
if ( strlen($expiry_day) == 1 ) {
$expiry_day = "0".$expiry_day;
}
if ( strlen($expiry_month) == 1 ) {
$expiry_month = "0".$expiry_month;
}
if ( strlen($expiry_year) == 1 ) {
$expiry_year = "0".$expiry_year;
}
// now able to convert expiry date to yymmdd format
$expiry_yymmdd = $expiry_year.$expiry_month.$expiry_day;
return($expiry_yymmdd);
}
|
Here's a program to demonstate that it works for a single given "random" date...
<?php
function ConvertExpiryDateToYYMMDD($theDate) {
// prepare to convert expiry date to yymmdd format
// handle dd/mm/yy dates including single digits for dd, mm, yy
// - e.g. 06/06/03, 6/6/03, 06/6/03, 6/06/03, 06/06/3 etc.
$position_of_first_slash = strpos($theDate, "/");
$expiry_day = substr($theDate, 0, $position_of_first_slash);
$expiry_mm_yy = substr($theDate, $position_of_first_slash + 1,
strlen($theDate));
$position_of_second_slash = strpos($expiry_mm_yy, "/");
$expiry_month = substr($expiry_mm_yy, 0, $position_of_second_slash);
$expiry_year = substr($expiry_mm_yy, $position_of_second_slash + 1,
strlen($theDate));
// if any of dd, mm or yy are single digits then add a leading zero
if ( strlen($expiry_day) == 1 ) {
$expiry_day = "0".$expiry_day;
}
if ( strlen($expiry_month) == 1 ) {
$expiry_month = "0".$expiry_month;
}
if ( strlen($expiry_year) == 1 ) {
$expiry_year = "0".$expiry_year;
}
// now able to convert expiry date to yymmdd format
$expiry_yymmdd = $expiry_year.$expiry_month.$expiry_day;
return($expiry_yymmdd);
}
/*
MAIN PROGRAM
*/
echo (ConvertExpiryDateToYYMMDD("30/1/05"));
?>
|
|
|