Click here to Skip to main content
15,917,455 members
Please Sign up or sign in to vote.
1.89/5 (3 votes)
See more: , +
Hai friends,

Actually my problem is that,i have to subtract two different time which stored in database as nvarchar using query string. main problem is that cast convertion is error. how to subtract two different NVARCHAR values of time using query string?
Anybody please help me.... if you are having any doubts regarding question please ask me..
Posted
Updated 26-Feb-14 19:18pm
v4
Comments
[no name] 27-Feb-14 1:21am    
Can you enter the sample data that you wants to use for substraction
Helen Paulose 27-Feb-14 2:15am    
i have to subtract 01:00:00 and 02:00:00 which is stored in the database as nvarchar
[no name] 27-Feb-14 2:52am    
DECLARE @FROMTIME VARCHAR(50)='02:00:00:00'
DECLARE @TOTIME VARCHAR(50)='01:00:00:00'

SELECT CONVERT(VARCHAR,((CONVERT(DATETIME,@FROMTIME,114) - CONVERT(DATETIME,@TOTIME,114))),114)


Solved your problem

No details, no direct help/answer.

Please, use SearchBox[^] on the right-top corner of this site. There are tons of examples.
Please be more specific and provide more details next time. It should be: 1) sample data and 2) expected output, at least.
 
Share this answer
 
Its always advised to keep Date datatype instead of NVarchar when handling dates.

Anyways you can try DATEDIFF method with a Convert to accomplish it.

Something like

SQL
Select DATEDIFF (MINUTE,DateColumn1,DateColumn2) from TableName;//without using Convert or Cast 
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900