Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 converting dB date to actual date

Author  Topic 

Pasi
Posting Yak Master

166 Posts

Posted - 2014-03-24 : 15:10:14
HI All,

The dB dates are store in db as 20140303 when I bring this to my application to pick a date, the apps shows the date as 20140303 how can I change this to show in the format 03/03/2014 in my application?

Thanks!!

James K
Master Smack Fu Yak Hacker

3873 Posts

Posted - 2014-03-24 : 15:18:48
Is it stored as a number, or as a string? If it is string,
CONVERT(VARCHAR(10),YourDateColumn,102)
If it is stored as an int,
CONVERT(VARCHAR(10),CAST(YourDateColumn AS VARCHAR(10)),102)


The expert recommendation is that you should store dates as DATE or DATETIME (or one of the other date/time data tyes), which would avoid the need for this type of conversions.
Go to Top of Page

Pasi
Posting Yak Master

166 Posts

Posted - 2014-03-24 : 15:49:01
Thanks Jmaes!! Sorry but Here is what I have: (formula)
---> {XXXBO_Hosp_Charges_.Admitt_Date} in date( {?From} to {?To})

The admitt_date since its in db is in string format but in my apps appears as a date. the "to" and "from" are date fields but I am not sure how to put these into the formula you gave me?

Pasi

quote:
Originally posted by James K

Is it stored as a number, or as a string? If it is string,
CONVERT(VARCHAR(10),YourDateColumn,102)
If it is stored as an int,
CONVERT(VARCHAR(10),CAST(YourDateColumn AS VARCHAR(10)),102)


The expert recommendation is that you should store dates as DATE or DATETIME (or one of the other date/time data tyes), which would avoid the need for this type of conversions.

Go to Top of Page

Bustaz Kool
Master Smack Fu Yak Hacker

1834 Posts

Posted - 2014-03-24 : 18:48:54
The larger question is not "how" to format the date but "where". Let the presentation layer (application?) do this work; not the database.

===============================================================================
“Everyone wants a better life: very few of us want to be better people.”
-Alain de Botton
Go to Top of Page
   

- Advertisement -