As SQL Server returns timestamp like 'Nov 14 2011 03:12:12:947PM', is there some easy way to convert string to date format like ‘Y-m-d H:i:s’.
So far I use
date('Y-m-d H:i:s',strtotime('Nov 14 2011 03:12:12:947PM'))
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
SQL Server’s
TIMESTAMPdatatype has nothing to do with a date and time!It’s just a hexadecimal representation of a consecutive 8 byte integer – it’s only good for making sure a row hasn’t change since it’s been read.
You can read off the hexadecimal integer or if you want a
BIGINT. As an example:The result is
In newer versions of SQL Server, it’s being called
RowVersion– since that’s really what it is. See the MSDN docs on ROWVERSION:So you cannot convert a SQL Server
TIMESTAMPto a date/time – it’s just not a date/time.But if you’re saying timestamp but really you mean a
DATETIMEcolumn – then you can use any of those valid date formats described in the CAST and CONVERT topic in the MSDN help. Those are defined and supported “out of the box” by SQL Server. Anything else is not supported, e.g. you have to do a lot of manual casting and concatenating (not recommended).The format you’re looking for looks a bit like the ODBC canonical (style = 121):
gives:
SQL Server 2012 will finally have a
FORMATfunction to do custom formatting……