Link to home
Start Free TrialLog in
Avatar of route217
route217Flag for United Kingdom of Great Britain and Northern Ireland

asked on

Amend date field in SQL Statement

Hi Experts

I have the following line of SQL Statement

ISDATE(created_dateonly) as created_date_only,
which in column Created_dateonly is the date in format 2012-12-06 and in column Created_Date_only shows 1 and 0.....

how can i change the SQL so in column Created_date_only the date is in the format 25/09/2013...
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

you may want to use this article to handle date/time vs string correctly:
https://www.experts-exchange.com/Database/Miscellaneous/A_1499-DATE-and-TIME-don%27t-be-scared-and-do-it-right-the-first-time.html

you may try this expression:
CASE WHEN ISDATE(created_dateonly) = 0 then created_dateonly
   ELSE CONVERT(VARCHAR(10), CASE WHEN ISDATE(created_dateonly) = 1 then created_dateonly ELSE NULL END, 103) end  

Open in new window

Avatar of route217

ASKER

hi angeliii

the expression works but the new column created to the right the date is still in the format 2012-12-06.......not as 06/12/2012...
ASKER CERTIFIED SOLUTION
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
hi angeliii

you're second expression works...but a hand full of date s are still appearing in the  format 2012-06-12......hmmmmmm
can you show examples?
maybe isdate() is returning 0 ...
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
angeliii

correct the is date is returning a 0....
then let's check on which values it's doing that.
hang fire...