Date Format

  • Hi,

    I am very new to SQL and learning as I go. I am creating some very basic php pages that gather and display data from an SQL server. I am having trouble formatting the dates though.

    I would like my date to be in the format of DD/MM/YY with no time stamps. They currently show as MM/DD/YYY HH:MM:SS

    My code is:

    While ($row = mysql_fetch_array($result)) {

    exho "<b>Supplier: " .$row{'Supplier_Name'}. "

    Start Date: </b>" .$row{'Start_Date}."

    "; }

    Thanks

  • You might be better asking this question on a PHP forum.

    Are you using MS SQL Server or MySQL?

    If you are using MS SQL Server then the following will convert a date into UK format (dd/mm/yyyy) but I doubt it will work if you put it into the code you posted - you might have to go back to where you are initially populating the array and amend this query.

    convert(varchar(10),Start_Date,103) as Start_Date

  • try the below query to get result in DD/MM/YY format.

    select LEFT(convert(varchar(10), @date, 103),6) + Right(Year(@date)+ 1,2)

  • johnwalker10 (12/23/2015)


    try the below query to get result in DD/MM/YY format.

    select LEFT(convert(varchar(10), @date, 103),6) + Right(Year(@date)+ 1,2)

    Gosh, no... Never do date/time formatting for a GUI from SQL Server. Let the GUI do the formatting so that local datetime settings can prevail. As previously suggested on this thread, a PHP forum would be the best place to discover how to do this.

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply