Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 797
  • 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


Featured Post


Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

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