I tried searching the forums but had no luck.

I've got a field containing a birth date stored in a MySQL database in DATE format. When extracted it looks like 'YYYY-MM-DD'.
If I try to parse this string using date() or strftime() and the date is actually before 1970-01-01 I get different results but none of them is the correct one.
It seems like when converting the date to a timestamp, the returned integer is a wrong value and not the actual representation of the date (maybe because timestamps start at 1970-01-01 ?)

is there any way to extract the day, month and year from a date before 1970-01-01 ??

    Hello,

    To do what you want, you can simply use sscanf() function (That PHP function works like C sscanf() ). Check this:

    $mandate = "1902-01-15"; // Or the result of a SQL query...
    list($month, $day, $year) = sscanf($mandate,"%d-%d-%d");
    

    The three variables $month, $day, $year are respectively set to the values read from the string $mandate. "%d" means that a numeric value (d stands for decimal) must be read.

    Hope this helps 🙂

      Yes, that's a good idea. But I was looking for something that I could use easily in a Smarty plugin.
      As of now I decided to do a simple explode() on the date since I get the dates all in the same format from the SQL queries and split them up in day, month and year.

        Write a Reply...