|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
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 ![]() |
|
#2
|
||||
|
||||
|
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.
__________________
Up the Irons What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home. "Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest Down with Sharon Osbourne Puzzle of the Month solved by sizeablegrin, etienne141 and L7Sqr, superior C/C++ programmers of the month |
|
#3
|
|||
|
|||
|
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 |
![]() |
| Viewing: Dev Shed Forums > Databases > MS SQL Development > problem with covert function! |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|