Monday, February 13, 2012

ADO adDBtimeStamp maps to a DATETIME type in SQL Server

I have a smalldatetime in SQL table, and I want to get this datetime
in the format yyyy-mm-dd hh:mm, but acorss ADO, I got yyyy-m-d
format. This is not I will. One way I thought is converting the
smalldatetime to a string. And this's not a elegant way. Because in
the case, I have to change many sql sentences to fix the problem.
Any suggestion? Thanks in advance.
You are correct that date/time formatting should be done in application code
rather than SQL Server so this isn't really a SQL Server question. What
language are you using?
In VbScript, you could do something like:
MyDateTimeString = _
DatePart("yyyy", myDateTime) & "-" & _
Right("0" & DatePart("m", myDateTime), 2) & "-" & _
Right("0" & DatePart("d", myDateTime), 2) & _
" " & _
Right("0" & DatePart("h", myDateTime), 2) & ":" & _
Right("0" & DatePart("n", myDateTime), 2)
In a C#:
MyDateTimeString = myDateTime.Format("yyyy-MM-dd HH:mm");
In a VB.Net:
MyDateTimeString = myDateTime.Format("yyyy-MM-dd HH:mm")
Hope this helps.
Dan Guzman
SQL Server MVP
<1983ddd@.gmail.com> wrote in message
news:1184992038.598841.62590@.x35g2000prf.googlegro ups.com...
>I have a smalldatetime in SQL table, and I want to get this datetime
> in the format yyyy-mm-dd hh:mm, but acorss ADO, I got yyyy-m-d
> format. This is not I will. One way I thought is converting the
> smalldatetime to a string. And this's not a elegant way. Because in
> the case, I have to change many sql sentences to fix the problem.
> Any suggestion? Thanks in advance.
>

No comments:

Post a Comment