• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 806
  • Last Modified:

Format DATETIME field in a Select Statement from MS SQL 2005?

One of them any columns of information I need from a MSSQL database contain DATETIME, I'm pulling this off of a server that is not local and importing the results into a local MySQL Server. I have two problems. First of all, the MSSQL Server is in UTC time, and I am in Eastern time, I have included what I use to fix this problem, I need to know now how to convert the Fields from MSSQLs format, to MySQL's:
DateTime in MSSQL:
4/3/2009 2:43AM
DateTime in MySQL (what I need the output from MSSQL to look like):
2009-04-03 02:43:00

Help would be much appreciated
This is how I convert from UTC to Eastern time:
declare @utcoffset datetime;
set @utcoffset = cast(getutcdate() - getdate() as decimal(12,7));
Then when I select a datetime field I do:
select field - @utcoffset, fiel2, field3 from table.
thus I'm assuming I would need to do select convert(field) - @utcoffset, or select convert(field - @utcoffset).

Open in new window

1 Solution
Guy Hengel [angelIII / a3]Billing EngineerCommented:
in mssql, to get the format you got in mysql, use this expressoin:
CONVERT(VARCHAR(20), your_date_time, 120)

Open in new window

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now