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, 2022 in Database by Vaani
• 7,070 points
1,344 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, 2022 by Neha
• 9,020 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, 2022 in Database by Kithuzzz
• 38,000 points
786 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, 2022 in Database by Kithuzzz
• 38,000 points
819 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, 2022 in Database by Kithuzzz
• 38,000 points
775 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, 2022 in Database by Kithuzzz
• 38,000 points
412 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, 2022 in Others by nisha
• 2,210 points
590 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, 2022 in Database by Neha
• 9,020 points
756 views
0 votes
1 answer

Difference between datetime and timestamp in sqlserver?

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

answered Feb 16, 2022 in Database by Vaani
• 7,070 points
4,908 views
0 votes
1 answer

How to convert DateTime to VarChar

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

answered Feb 23, 2022 in Database by Neha
• 9,020 points
1,192 views
+1 vote
1 answer

How to Insert date value in SQL table

Always use ANSI default string literal format for date i.e. YYYY-MM-DD like below. INSERT ...READ MORE

answered Feb 17, 2022 in Database by Neha
• 9,020 points
177,967 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, 2022 in Database by Neha
• 9,020 points
1,987 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