Click here to Skip to main content
12,951,619 members (62,377 online)
Rate this:
 
Please Sign up or sign in to vote.
See more:
how to get today date in storeprocedure coding.
when using command text this will done using datetime.Today().
but how to get today date in storeprocedure?

i have select checktime using query ..
select  top 1 @CheckType=CheckType,@CheckTime=CheckTime,@Userid=Userid,@Logid=Logid from Checkinout order by logid desc


now if checktime is today date then update record .for this i have do ....
if(@CheckTime = getdate())
	begin
UPDATE       Biometrics
SET                [Name] = @Name,[Date]=InTime ,Group_Id = @Groupid, OutTime = @CheckTime, Duration=DATEDIFF(mi, InTime , @CheckTime)  where  id=@id
	end

but my record not updated.what is problem?
Posted 30-Jan-13 2:32am
Updated 30-Jan-13 2:43am
v3
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

In SQL you can do
SELECT GETDATE() AS TodaysDate
  Permalink  
Comments
Member 9511889 30-Jan-13 8:40am
   
i have select checktime using query ..
select top 1 @CheckType=CheckType,@CheckTime=CheckTime,@Userid=Userid,@Logid=Logid from Checkinout order by logid desc


now if checktime is today date then update record .for this i have do ....
if(@CheckTime = getdate())
begin
UPDATE Biometrics
SET [Name] = @Name,[Date]=InTime ,Group_Id = @Groupid, OutTime = @CheckTime, Duration=DATEDIFF(mi, InTime , @CheckTime) where id=@id
end
but my record not updated.what is problem?
ryanb31 30-Jan-13 8:49am
   
GetDate() includes the time so that is why @CheckTime is not working. What is in your @CheckTime?
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 4

Replace ur condition wid below one


if( Convert(varchar,@CheckTime,101) = Convert(varchar,getdate(),101) )
begin
UPDATE  Biometrics
SET  [Name] = @Name,[Date]=InTime ,Group_Id = @Groupid, OutTime = @CheckTime, Duration=DATEDIFF(mi, InTime , @CheckTime)  where  id=@id
    end



plz vote and accept ans if it helps u :)
if it works for u i wll explain u y ur code wsnt workin

happy coding buddy :)
  Permalink  

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

    Print Answers RSS
Top Experts
Last 24hrsThis month
OriginalGriff 6,229
CHill60 3,490
Maciej Los 3,083
Jochen Arndt 1,975
ppolymorphe 1,880


Advertise | Privacy | Mobile
Web01 | 2.8.170525.1 | Last Updated 30 Jan 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100