2 Replies - 657 Views - Last Post: 18 July 2015 - 03:01 PM

#1 elaraby77   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 11-May 14

Problem in date datatype in sql server

Posted 18 July 2015 - 02:19 PM

:surrender:I have database named Scientists and table Scientist
CREATE TABLE Scientist
(
Scientist_No int NOT NULL PRIMARY KEY,
Scientist_Name nvarchar(50) NOT NULL,
Birth_Date date NOT NULL,
Gender nvarchar(10) NOT NULL,
Nationality nvarchar(50) NOT NULL,

)

When i need insert by insert statement
insert into Scientist
(Scientist_No,Scientist_Name,Birth_Date,Gender,Nationality)
values
(9,'Hani','19-5-1950','Male','Egypt')


This message appears

Msg 241, Level 16, State 1, Line 1
Conversion failed when converting date and/or time from character string.


i need insert date by this format (dd-mm-yyyy)
how make that in insert statement

note i have SQL server 2008

Excuse my English is not my native language
i need help

Is This A Good Question/Topic? 0
  • +

Replies To: Problem in date datatype in sql server

#2 andrewsw   User is online

  • RequestedRangeNotSatisfiable
  • member icon

Reputation: 6552
  • View blog
  • Posts: 26,562
  • Joined: 12-December 12

Re: Problem in date datatype in sql server

Posted 18 July 2015 - 02:31 PM

If you need to insert as dd-mm-yyyy then you need to use convert as demonstrated here at SO:

Quote

insert table1 (approvaldate)
values (convert(datetime,'18-06-12 10:34:09 PM',5));

This post has been edited by andrewsw: 18 July 2015 - 02:31 PM

Was This Post Helpful? 0
  • +
  • -

#3 elaraby77   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 11-May 14

Re: Problem in date datatype in sql server

Posted 18 July 2015 - 03:01 PM

Thank yooooooooou
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1