I have designed an employee portal. The moment the user logs in and logs out the current datetime will be stored.
Before the user logs out I should ensure whether he/she has entered the work done form for that day.
I wrote
select count(*) from workdone where work_date_time=getdate()
If there are any rows that means he/she has filled up the form else not filled.
But the query is comparing the date as well as time.
I want to compare only the date.
How should I reframe the query
Regards
cmrhema
Quote:
Originally Posted by cmrhema
Hi,
I have designed an employee portal. The moment the user logs in and logs out the current datetime will be stored.
Before the user logs out I should ensure whether he/she has entered the work done form for that day.
I wrote
select count(*) from workdone where work_date_time=getdate()
If there are any rows that means he/she has filled up the form else not filled.
But the query is comparing the date as well as time.
I want to compare only the date.
How should I reframe the query
Regards
cmrhema
SQL Server stores dates and time together. Depending on your application and how you are passing your date parameter in as part of your where clause (ie which part of the world you are in) you need to be mindful of your regional settings and look at the CONVERT function in SQL Server
SELECT CONVERT(char(10), GETDATE(), 103)
Will return getdate as character conversion based on the UK regional setting (103)
Regards
Jim :)
No comments:
Post a Comment