Blind date()

Applaud the buddy-buddy relationship of PHP and MySQL all you want. One thing about SQL has always bothered me: dates. You can add them to your database however you want, but it will always be spit out ‘YYYY-MM-DD.’ With dashes, leading zeros, and year in front. Only three tribes of sub-Saharan Africa write dates that way.

Wouldn’t it be great if PHP could pick up the slack with a do-all function? If they can include functions like jdtojewish() ((Hint: Much of PHP was developed in Israel.)) , there should be something like

[code lang="php"]
$crappySQLdate = $row['crap_date'];
$awesomeDate = convert_date($crappySQLdate, 'm/d/Y');[/code]

Tough. In this cold, mean world, you have to break the date into month, day, and year variables, pop each into a function to generate the number of seconds since the Unix epoch, then convert it to a date format of your choosing:

[code lang="php"]
$crappySQLdate = $row['crap_date'];
$day = date_parse($crappySQLdate);
$awesomeDate = date('m/d/Y', mktime(0, 0, 0, $day['month'],
      $day['day'], $day['year']));[/code]

Next up, printing text one character at a time using nested ‘for’ loops.

Leave a Reply