I am doing it with phone numbers (xxx.xxx.xxxx) and zip codes (xxxxx-xxxx) already, and i basically copied and pasted the script and made the changes so i'm not sure why its not working with the date.. function Dates($sDate) { $sDate = ereg_replace("[^0-9]",'',$sDate); if(strlen($sDate) != 8) return(False); $sMonth = substr($sMonth,0,2); $sDay = substr($sDay,2,2); $sYear = substr($sYear,4,4); $sDate = $sMonth . "/" . $sDay . "/" . $sYear; return($sDate); } PHP: <? if ($row['lic_dt'] > 0) { echo "This software package will expire on " . Dates($row['lic_dt']) . "."; } ?> PHP: All the output shows is "This software package will expire on //. Thanks in advance for the help!
The error is here: $sMonth = substr($sMonth,0,2); $sDay = substr($sDay,2,2); $sYear = substr($sYear,4,4); PHP: In the substr() calls, none of the variables exists. Try replacing them all with $sDate.
ahhhhh... dang. I knew it was something easy.. mods can delete this thread if they want as it only makes me look like a simpleton :-D
Btw, you can do the same with RegEx: function Dates($date) { $date = preg_replace('/\D/', null, $date); return strlen($date) == 8 ? preg_replace('/^(\d{2})(\d{2})(\d{4})$/', '$1/$2/$3', $date) : false; } PHP:
What is the $sDate that is being passed phrase as? Unixtime? function($sDate) { $sDate = strtotime($sDate); return date('m/d/y',$sDate); } PHP:
No, it is just a number that i have in a database, like 01012007 or whatever. One more question on this.. I want to make an edit box that has three text fields, one for the month, date and year. To do this I need to separate the values in the database, which is already done with the dates() function. However, I can't figure out how to output the $sDay, $sMonth and $sYear. Any help would be great! Thanks, Nathan