Lost Date Formatting
I've had the same code for years for displaying a reformatted datestamp from a database. For unknown mysterious reasons, without touching the code, it stopped working correctly.
Code 1:
Quote: $result = mysql_query ($query);
while($row = mysql_fetch_array($result)) {
$month = substr($row["lastupdated"], 4, 2);
$day = substr($row["lastupdated"], 6, 2);
$year = substr($row["lastupdated"], 0, 4);
$date = $month."/".$day;
print $date;
This used to take an 8 digit datestamp like "20051005" and print it like "10/05" but now it spits out something like this "-1/0-" (may be slightly different output but screwed up none the less)
Another similar example is on another page, my the code should print it all out nicely.
Code 2:
Quote: echo "Last Updated:";
if ($myrow["lastupdated"] == "00000000") {
echo ("Unknown");
} else {$month = substr($myrow["lastupdated"], 4, 2);
$day = substr($myrow["lastupdated"], 6, 2);
$year = substr($myrow["lastupdated"], 0, 4);
$date = $month."/".$day."/".$year;$months = array("January", "Feburary", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
$month = $month - 1;
$dmon = $months[$month];echo "".("$dmon $day, $year");
It should print "20051005" as something nice but it's spitting out something like "10-, 2005" (may be slightly different output but screwed up none the less)
Anybody have any idead of how all this may have changed since I didn't change my php code in years? Or how I can fix it? Thanks
Greg K posted this at 20:14 — 5th October 2005.
He has: 2,145 posts
Joined: Nov 2003
Check with your hosting company to see if they made any changes to the settings to PHP or perhapps installed a newer version. For me, it is working both on my laptop (running in Zend Studio) and when I uploaded it to my server.
-Greg
fifeclub posted this at 16:38 — 7th October 2005.
He has: 688 posts
Joined: Feb 2001
Apparenty by some mysteriously unknown reason because I definitely didn't do anything to it... my 8 digit datestamps have all been converted to 19 character timestamps. So as an example for October 7th, 2005, my script was expecting something like this:
20051007
But was now receiving something like this:
2005-10-07-12:34:56
My host (whom I was happy with) offered absolutely no explanation for what happened. It appears now that my code above is off by digits because of those dashes and I suppose I could just alter my code slightly to compensate for the digit shifts. So it doesn't seem like the end of the world but I'm still a little pissed off that changes were made to my database without my actions or permission, which rendered my scripts useless without warning. What the hell?
Greg K posted this at 20:07 — 7th October 2005.
He has: 2,145 posts
Joined: Nov 2003
If it was a change in how the data came fromt he database, most likely their either adjusted a setting on the database or maybe upgraded versions. The later they may not have realized that the upgrade make the change.
-Greg
Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.