Last post Feb 16, 2017 04:08 AM by OneDaoVN
Feb 15, 2017 09:20 AM|tangara|LINK
Hi, I have this column name -
[IssuerSubmitDate] (datetime, null),
Now, I tried to insert the data directly in my MS SQL 2008 but I do not know what is the format based on the datetime.
Can someone advise me pls ?
I have tried out
but it gave me this error :
The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.
Feb 15, 2017 09:27 AM|oned_gk|LINK
Dont worry about date format, simply use parameterize query.
Pass date value (not string) in your c#/VB code.
DateTime dt = DateTime.Now;
DateTime dt = DateTime.ParseExact("27/01/2017","dd/MM/yyyy",null);
Feb 15, 2017 09:30 AM|tangara|LINK
I am trying to hardcode it inside my Database. How should I put the date then ?
Feb 15, 2017 09:39 AM|oned_gk|LINK
Use Cast/Convert with appropriate format
Feb 15, 2017 10:17 AM|PatriceSc|LINK
For literal values use 'YYYYMMDD'or 'YYYY-MM-DD' :
SELECT * FROM sys.objects WHERE create_date>='2016-10-01'
always works and is October 1st.
If using '01-10-2016' it might be taken as october 1st or january 10 depending on SQL Server settings.
Edit: so in your caseymy understanding is that you want to do something such as :
INSERT INTO YourTable(DateColumn) VALUES ('2017-01-12')
Feb 16, 2017 04:08 AM|OneDaoVN|LINK
You would have the field as datetime in the table and then insert it normally. It will save in the database as '2017-02-04 04:33:26.600' for example. And then you can output whichever format you like using the format function in vb.net or C#.