In my application I want to enable/disable attendance button. I am recording marked attendance dates in GMT. Few users who are come in mid-shift are finding this attendance button enabled in alternate days. For example if any user has marked attendance today, he might not be able to mark attendance next day because button is disabled as it is still finding the same GMT date when last attendance was marked.
I am using below code to match user's last marked attendance with current GMT date.
Declare @Minutes numeric(10,2)
Declare @CurrentDate DateTime
SET @Minutes = DATEDIFF(minute, GetUTCDate(), GetDate())
SET @CurrentDate = Convert(Varchar(20), DateAdd(minute, @Minutes, GetUTCDate()),111)
With this code, the @CurrentDate is always obtained with 12:00 AM time. I feel there is some mistake in this code.
I also want to know whether the above code is required at all because I just want to match the last recorded GMT date with the current GMT date.
Please note that GetDate alone will not work because this is a ASP.NET application and our database server is in US whereas clients are in other nation.
I am using SQL Server 2005 database. Please suggest solutions for both SQL Server 2005 and 2008.