Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

mySQL date format....

  • 29-06-2006 02:56PM
    #1
    Registered Users, Registered Users 2 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, Registered Users 2 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, Registered Users 2 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