Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
SergioM
Posting Yak Master
170 Posts |
Posted - 2013-08-12 : 14:00:43
|
I have a datetime field in my table. I call that field with a different software & it comes out in an unexpected format.My db table stores it in unix format: 2013-08-12 09:29:00.000But the software pulls it as: 8/12/2013 9:29:00 AMI know it's possible, but I don't know how. How do I explicitly call it (in SQL) as a unix timestamp. Or how do I convert to a unix timestamp from the available data above? Thanks-SergioI use Microsoft SQL 2008 |
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
SergioM
Posting Yak Master
170 Posts |
Posted - 2013-08-12 : 14:17:01
|
I simplified it by calling it a software, but in reality I'm having this issue with autohotkey. This is a pretty obscure programming language, but it does use the Windows ADO COM objects to read/write to MSSQL. I'm using it as a bridge between my MSSQL db & MySQL db. So I can be sure it's not a display issue. Is there a way to explicitly call a datetime in Unix format? Or alternatively to convert an unexpected format to unix datetimeformat?-SergioI use Microsoft SQL 2008 |
|
|
MuMu88
Aged Yak Warrior
549 Posts |
Posted - 2013-08-12 : 14:27:15
|
quote: Originally posted by SergioM I know it's possible, but I don't know how. How do I explicitly call it (in SQL) as a unix timestamp. Or how do I convert to a unix timestamp from the available data above? Thanks-SergioI use Microsoft SQL 2008
Check this site:http://technet.microsoft.com/en-us/library/aa226054(v=SQL.80).aspxUse CONVERT() like examples shown below:[CODE]DECLARE @DateTime DATETIME = getdate();SELECT CONVERT(CHAR(30),@DateTime, 120), 120UNIONSELECT CONVERT(CHAR(30),@DateTime, 109), 109UNIONSELECT CONVERT(CHAR(30),@DateTime, 111), 111UNIONSELECT CONVERT(CHAR(30),@DateTime, 112), 112UNIONSELECT CONVERT(CHAR(30),@DateTime, 126), 126UNIONSELECT CONVERT(CHAR(30),@DateTime, 103), 103 [/CODE] |
|
|
SergioM
Posting Yak Master
170 Posts |
Posted - 2013-08-13 : 12:09:49
|
quote: Originally posted by MuMu88Use CONVERT() like examples shown below:
Bingo! Thanks! I would never think to convert to a char, but since datatypes are not explicitly cast in autohotkey, it reads it exactly as I need it. Thanks again!-SergioI use Microsoft SQL 2008 |
|
|
|
|
|
|
|