How Can I use Date Datatype in sql server

0 votes

When I'm trying to create column in table with data type "Date" it is giving me error 

Create table Sales (
Order_ID INT Primary Key,
Product_name varchar(100) ,
isbn varchar(100) ,
Customer_ID INT Foreign key references Customer,
Order_date date,
);

I need to get date of something which is before created one

The query indicates to find the date before 2nd August

The code I have used is:

Insert Into Orders(Order_ID, Product_name, isbn, Customer_ID, Order_date) values (1, 'Design User Interface',9345678210123, 1, '02-08-2015'); 
Insert Into Orders(Order_ID, Product_name, isbn, Customer_ID, Order_date) values (2, 'Fire',9654693261489, 1, '05-08-2015'); 
Insert Into Orders(Order_ID, Product_name, isbn, Customer_ID, Order_date) values (3, 'The Odyssey',9654864332511, 2, '01-08-2015'); 
Insert Into Orders(Order_ID, Product_name, isbn, Customer_ID, Order_date) values (4, 'Anatomy',9654877777755, 2, '30-07-2015'); 
Insert Into Orders(Order_ID, Product_name, isbn, Customer_ID, Order_date) values (5, 'Surgery',9654864951753, 2, '01-07-2015'); 
it is accepting only the first 3 data insertion and last two it is reporting error
Feb 9 in Database by Vaani
• 7,020 points
270 views

1 answer to this question.

0 votes
There's problem in all of them and not just the last two.

The error is due to the DATE FORMAT
Your system is taking a different date format while your data has a different one.

Your dates are as MM-DD-YYYY which depends on the culture of your system,

While using dates, it is better to use culture independent formats like the universal format:

2020-10-05 is 5th of October 2020
 

Using YYYY-MM-DD format might actually work out for your query.
answered Feb 9 by Neha
• 8,940 points

Related Questions In Database

0 votes
0 answers

How can I show the table structure in SQL Server query?

Query: SELECT DateTime, Skill, Name, TimeZone, ID, User, ...READ MORE

Aug 11 in Database by Kithuzzz
• 20,660 points
108 views
0 votes
0 answers

How can I set a custom date time format in Oracle SQL Developer?

Date values are shown in Oracle SQL ...READ MORE

Aug 12 in Database by Kithuzzz
• 20,660 points
103 views
0 votes
0 answers

How do I query for all dates greater than a certain date in SQL Server?

I tried this: SELECT * FROM dbo.March2010 A WHERE ...READ MORE

Aug 29 in Database by Kithuzzz
• 20,660 points
72 views
0 votes
0 answers

How can I get column names from a table in SQL Server?

I want to search for every column's ...READ MORE

Sep 3 in Database by Kithuzzz
• 20,660 points
51 views
0 votes
1 answer

How Can I use "Date" Datatype in sql server?

Your dates are interpreted as MM-DD-YYYY. This ...READ MORE

answered Jun 21 in Others by nisha
• 2,190 points
78 views
0 votes
1 answer

How to rename a column in a database table using SQL?

For SQL Server, use sp_rename USE AdventureWorks; GO EXEC sp_rename 'Customers.CustomerTerritory.TerritoryID', ...READ MORE

answered Feb 9 in Database by Neha
• 8,940 points
145 views
0 votes
1 answer

Difference between datetime and timestamp in sqlserver?

Timestamp is a synonym for rowversion, according ...READ MORE

answered Feb 16 in Database by Vaani
• 7,020 points
1,694 views
0 votes
1 answer

How to convert DateTime to VarChar

With Microsoft Sql Server: -- -- Create test case -- DECLARE ...READ MORE

answered Feb 23 in Database by Neha
• 8,940 points
130 views
0 votes
1 answer

LEFT JOIN vs. LEFT OUTER JOIN in SQL Server

At the top level there are mainly ...READ MORE

answered Feb 4 in Database by Neha
• 8,940 points
276 views
0 votes
1 answer

SQL Server replaces LEFT JOIN for LEFT OUTER JOIN in view query

You are getting the joins confused and ...READ MORE

answered Feb 4 in Database by Neha
• 8,940 points
289 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP