Answer the question
In order to leave comments, you need to log in
How to insert datetime in MSSQL?
There is a table with a DateTime field.
View request:
INSERT INTO test (created_at) VALUES ('2015-12-25T15:32:06.427');
INSERT INTO test (created_at) VALUES ('2015-12-25 15:32:06.427');
[S0003][242] Converting a varchar data type to a datetime data type resulted in an out of range value.
Answer the question
In order to leave comments, you need to log in
No need to force the base. Either correct the input data or conjure with string type casts. I recommend to deal with the input data of the request.
Convert the date/time to the standard format: 'yyyymmddhhmmss'
For the case of a single date, you can set: 'yyyymmdd'
In this format, there will never be a problem with writing the date/time.
INSERT INTO test (created_at) VALUES (CAST('2015-12-25 15:32:06.427' AS DateTime));
And we only store the timestamp in the database.
For comparisons and selections, it is enough (an integer in fact), and for output, we will convert it to the desired format.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question