Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

mySQL date format....

Options
  • 29-06-2006 2:56pm
    #1
    Registered Users Posts: 467 ✭✭


    Hi, i have a small problem.

    I'm saving the current date when saving information into my MySQL database by using "now()".
    The problem is it gives it to me in this format: YYYY-MM-DD
    Is there any way to change the format either when saving into the database or reading from the database? I'd like to change it to: DD-MM-YYYY
    I'm using PHP....
    Can anyone help?


Comments

  • Closed Accounts Posts: 4,655 ✭✭✭Ph3n0m


    http://ie.php.net/manual/en/function.date.php - no matter how you store the date, when reading it from the database you can manipulate it anyway you want


  • Registered Users Posts: 467 ✭✭nikimere


    i can change the current time easily after reading that but....
    i'm pulling the date from the db into a variable called $date

    [PHP]$today = date("m.d.y");[/PHP] is the example i want from your link

    how would i change this so it will change th format of $date ?


  • Closed Accounts Posts: 4,655 ✭✭✭Ph3n0m


    $date = "2000-12-23";
    echo $date;
    $today = date("m.d.y", strtotime($date));
    echo $today;

    I specified what $date was, but if its being fed from a db, it should work


  • Registered Users Posts: 467 ✭✭nikimere


    ah! nice one! thanks :)


  • Closed Accounts Posts: 70 ✭✭vito


    nikimere wrote:
    Hi, i have a small problem.

    I'm saving the current date when saving information into my MySQL database by using "now()".
    The problem is it gives it to me in this format: YYYY-MM-DD
    Is there any way to change the format either when saving into the database or reading from the database? I'd like to change it to: DD-MM-YYYY
    I'm using PHP....
    Can anyone help?

    alternatively, you can let mysql fomat the date for you:

    SELECT DATE_FORMAT(date, '%d-%m-%Y') FROM tablename WHERE...

    where 'date' is the fieldname of your date column and tablename is the name of your table.

    No php required to get the desired format!


  • Advertisement
Advertisement