Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4

Thread: Date conversion

  1. #1
    New Coder
    Join Date
    Oct 2007
    Posts
    73
    Thanks
    26
    Thanked 0 Times in 0 Posts

    Date conversion

    I'm displaying a list of events read from the database.
    I used the following to make it 'more readable'
    Code:
    $query = "SELECT DATE_FORMAT(datum, '%a %d %M %Y') as dedag FROM optredens WHERE datum > now() ORDER BY datum ASC";
    That gives me Sat 03 May 2008

    I would like this to be in Dutch (Za 03 mei 2008)
    Thought using strftime and setlocale would do the trick.
    This is what I came up with:
    PHP Code:
            }
        $query2 = "SELECT datum FROM optredens WHERE datum < now() ORDER BY datum DESC";
        $result2 = mysql_query($query2);

            if ( !$result2 ) {
                echo "error oprning database...<br>";
            } else {
            $numrows = mysql_num_rows($result2);
            if ( 0 == $numrows ) {
                echo "no entries found...";
            } else {
                echo "<span class='gigtitel'>Het verleden</span><br><br><table width='90%' border='0' align='center' id='optr'>";
                    echo "<tr id='row1'>
                        <th>Nummer</th>
                        <th>Datum</th>
                        </tr>";
                setlocale(LC_TIME, 'dutch'); 
                for ( $j=0; $j < $numrows; $j++ ) {

                    $datum  = mysql_result ( $result2, $j, "datum");
                    $nummer = $numrows-$j;
                    $dedag =  strftime("%a %d %b %Y", $datum);

    ?>
                         <tr><td class='optredentekst'><?php echo $nummer ?></td>
                            <td class='optredentekst'><?php echo $dedag ?></td>
                        </tr>
    Result: It's in Dutch! but not the data from the database

    21 wo 31 dec 1969
    20 wo 31 dec 1969
    19 wo 31 dec 1969
    18 wo 31 dec 1969
    17 wo 31 dec 1969
    16 wo 31 dec 1969
    etc...
    So I must be close to the solution.
    What am I doing wrong??

  • #2
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,093
    Thanks
    11
    Thanked 101 Times in 99 Posts
    strftime() requires a unix timestamp to work with, so try changing that from the DB ..

    "SELECT UNIX_TIMESTAMP(datum, '%a %d %M %Y') as dedag"

    unix timestamps only work with dates >= 1970 (or in your case 31/12/69 ) so if you have dates earlier than that you can try setting the locale in MySQL

    SET lc_time_names = 'nl_NL';
    SELECT DATE_FORMAT(NOW(), '%a %d %M %Y');
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)

  • Users who have thanked firepages for this post:

    friz (10-29-2007)

  • #3
    New Coder
    Join Date
    Oct 2007
    Posts
    73
    Thanks
    26
    Thanked 0 Times in 0 Posts
    got an error, but this worked
    Code:
    SELECT UNIX_TIMESTAMP(datum) AS dedag
    Thx!!!!

  • #4
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,093
    Thanks
    11
    Thanked 101 Times in 99 Posts
    DOH, sorry, forgot to remove the formatting which is not an option in UNIX_TIMESTAMP(), glad you got it sorted.
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •