I’m trying to get something like “20101231235959” (yyyyMMddhhmmss) from a datetime value in a SQL Server DB. This is the best I can come up with – concatenate “yyyyMMdd” with “hh:mm:ss” after stripping the colons:
CONVERT(varchar(25),Batch.ImagedTime,112) + REPLACE(CONVERT(varchar(25),Batch.ImagedTime,108),':','')
Background: I’m pulling batches of images from a remote instrument and want to organise them by the time they were taken. The local system is Windows 7, and colons are not allowed in directory names. I’d settle for a UNIX timestamp if I could get it, but would prefer to have the name somewhat normal-human-readable…
As far as I can tell from this list of datetime styles, there’s no way to persuade SQL Server 2008 to give me a time without colons, or for Windows 7 to let me create a directory with them, so it’s string-bashing in SQL or string-bashing in Java.
Have I missed something obvious?
Just a slight modification of your current way:
“String bashing” in Java would be better though: SQL Server should send raw data