TheUndecider
asked on
Format Date in SQL Stored Procedure
Hello, I have a simple question.
How do I format a date in a stored procedure that selects some records from a table? I need the format to be like this:
06/19/2008 0:00:00
Usually, I get the date value like this: 06/19/2008 12:00:00 AM. I am exporting these records through a dataset in a .NET application to a text file and I need the date format to be exacly what I need. I don't need the 12 or the AM/PM label. Also, the formatted date has to be a datetime field and not a text or varchar.
Thanks!
How do I format a date in a stored procedure that selects some records from a table? I need the format to be like this:
06/19/2008 0:00:00
Usually, I get the date value like this: 06/19/2008 12:00:00 AM. I am exporting these records through a dataset in a .NET application to a text file and I need the date format to be exacly what I need. I don't need the 12 or the AM/PM label. Also, the formatted date has to be a datetime field and not a text or varchar.
Thanks!
ASKER
Hello, thanks for replying. I tried your solution and I still get the date as before: 6/20/2008 12:00:00 AM. I still get the time as 12:00:00 AM.
We used to export from a MS Access query to a comma delimited text file and the format Access does for date is mm/dd/yyyy h:mm:ss. I need to recreate the same format but still keeping the date as a datetime field.
Right now the closest I've got is to do it like this:
(convert(varchar,mydatefie ld)) + ' 0:00:00'
However, this makes it a text field and when exporting to the text file this field gets enclosed with quotation marks and it should not.
We used to export from a MS Access query to a comma delimited text file and the format Access does for date is mm/dd/yyyy h:mm:ss. I need to recreate the same format but still keeping the date as a datetime field.
Right now the closest I've got is to do it like this:
(convert(varchar,mydatefie
However, this makes it a text field and when exporting to the text file this field gets enclosed with quotation marks and it should not.
I think it has to do w/ the transfer from the db to your interface code because what I posted shows 2008-06-20 00:00:00.000 in the database for me.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
select cast(convert(varchar(10), getdate(), 101) as datetime)