SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Zealot
    Join Date
    Apr 2013
    Posts
    104
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Change date format from sysdate() to D-M-Y

    Hi,

    I am storing date of new inserted records in mysql date columns "created_date"

    I am using sysdate() function to store date and it is working.

    Following is the date stored in "created_date" column.

    9/18/2013 12:00:00 AM

    I want to show date on webpage in D-M-Y format but by default it is coming in Y-M-D format. (2013-09-18)

    How to change format D-M-Y to Y-M-D

    Any idea?

    -Thanks

  2. #2
    SitePoint Enthusiast
    Join Date
    Jul 2013
    Location
    Voorheesville NY USA
    Posts
    88
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    There is plenty of documentation in the php manual on converting dates. Search for 'date'

  3. #3
    SitePoint Addict bronze trophy
    Join Date
    Apr 2013
    Location
    Ithaca
    Posts
    351
    Mentioned
    6 Post(s)
    Tagged
    1 Thread(s)
    Create a datetime object and use the format method, its simple:

    PHP Code:
    $time sysdate();
    $date = new DateTime($time);
    $formatDate $date->format('Y-M-D'); 
    mission completed.


Tags for this Thread

Bookmarks

Posting Permissions

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