Helpful Information
 
 
Category: MS SQL Development
problem with covert function!

Hello all:
we want to insert date into table testDate in Datetime or another dataType in field testDate and extract it in hijry Date format And compare it with two Date.
acording to the articles we insert it in to the table in nchar dataType and then we want to extract it in datetime dataType using convert function in sql server :

(( SELECT CONVERT(datetime, ' testDate', 131)
FROM testDate ))
that gives this error:

(( Server: Msg 241, Level 16, State 1, Line 1
Syntax error converting datetime from character string. ))

if we want to insert Date in datetime dataType it enter in gregorian Date format.
while we want Date in hijry format.
Sincerely Mohsen

:) :)

Are you sure that the data in the field testDate is in the correct format. Also, the field name should not be enclosed in quotes (i.e.):
SELECT CONVERT(datetime, testDate, 131)
FROM testDate
instead of
SELECT CONVERT(datetime, ' testDate', 131)
FROM testDate

Otherwise, it'll try to convert the literal string ' testDate', instead of the value from the column name

For the record, this statement:
SELECT CONVERT(datetime, '21/12/2003 12:34:56AM', 131)
works for me.

thank your for your attention ,yes it worked:SELECT CONVERT(datetime, '21/12/2003 12:34:56AM', 131)
I examined it many times and it worked but I am surprise when I use the field of a table of nchar type it doesn't work ,I should mention that I tested this suntax and it doesn't work too:(datetime, testDate, 131)
Sincerley yours Mohsen

thank your for your attention ,yes it worked:SELECT CONVERT(datetime, '21/12/2003 12:34:56AM', 131)
I examined it many times and it worked but I am surprise when I use the field of a table of nchar type it doesn't work ,I should mention that I tested this suntax and it doesn't work too:(datetime, testDate, 131)
Sincerley yours Mohsen

Can you give any examples of the column data? If the conversion above works then it must be the column data that is the problem.

Can you give any examples of the column data? If the conversion above works then it must be the column data that is the problem.dude, i know you are new to the forums, so i'll go easy on you, but do you really honestly think the original poster is still hanging around here after almost eight years waiting for a solution?

please, leave dormant threads alone

dude, i know you are new to the forums, so i'll go easy on you, but do you really honestly think the original poster is still hanging around here after almost eight years waiting for a solution?

please, leave dormant threads alone

I didn't even check the date. It appeared at the top of the list so I assumed it was new. Sorry!










privacy (GDPR)