Question

I am working on pulling some data in from a Rest-api into my MSSQL database. The issue I am having is the timestamp that I am being given from the api does not appear to be formatted correctly to just insert '2013-09-16T07:00:00+0000'.

example insert:

INSERT INTO [page_fan_adds_unique]([period], [title], [description], [value], [end_time])  
VALUES ('day', 'Daily New Likes', 'Daily: The number of new people who have liked your Page (Unique Users)','0', '2013-09-16T07:00:00+0000')

I know changing the format to 2013-09-16T07:00:00+00:00 works but I didn't want to have to manipulate the data before the insert.

Was it helpful?

Solution 2

This is what I did. from my PHP code I inserted that date [end_time] = CAST(STUFF('".."',23,3,':00')AS DATETIME2)"

Now when I write my "select" statements I just cast(end_time as datetime) I find that this is a lot easier than trying to cast a string into a datetime in sql.

OTHER TIPS

You cannot do this without formatting.

From the MSDN about TIMESTAMP:-

Is a data type that exposes automatically generated, unique binary numbers within a database. timestamp is generally used as a mechanism for version-stamping table rows. The storage size is 8 bytes. The timestamp data type is just an incrementing number and does not preserve a date or a time. To record a date or time, use a datetime data type.

You may use datetime data instead.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top