2

Hi i am reading a value from a table using SqlDatareader, problem is it is always formatting the value acording to the machine date format settings.

for example the original date format in the source table is saved as yyyy/mm/dd

when i use SqlDatareader.GetValue in a machine that has date set as MM/dd/YY it is atutomatically converted to that format

is there anyway to retrive the date value with the original date formatting intact?

thanks

2 Answers 2

5

There is no "original date formatting", dates are kept internally as numbers, not strings.

Within a SQL query, you can choose the output formatting with

CONVERT(varchar(30), theColumn, nnn)

where "nnn" is one of the common date formats listed here: MSDN.

Personally I find that page confusing, so another (more useful) page is here: SQL Server Helper. From that page:

CONVERT(VARCHAR(20), GETDATE(), 100) 

will return 'Jan 1 2005 1:29PM'

Sign up to request clarification or add additional context in comments.

Comments

0

Probably not what you're looking for. But if you want to store the formatted date time, may be you should rather use VARCHAR or CHAR(N) as the field type. I would think the DATETIME field is to store datetime and the format it self isn't that important (or what it is meant for). However, you could reconvert it back to that format in C#.

1 Comment

Never store a datetime as a formatted string (excuse the hyperbole).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.