Solved

Handling GMT date issue to enable/disable button

Posted on 2013-05-20
3
423 Views
Last Modified: 2013-06-02
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)

Open in new window


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.
0
Comment
Question by:rpkhare
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 29

Assisted Solution

by:QPR
QPR earned 250 total points
ID: 39182537
Your convert to varchar 111 is truncating your date to yyyy-mm-dd which is why you have no minutes
0
 
LVL 29

Expert Comment

by:QPR
ID: 39182548
Is this what you need?

Declare @Minutes numeric(10,2)
Declare @CurrentDate DateTime
SET @Minutes = DATEDIFF(minute, GetUTCDate(), GetDate())
SET @CurrentDate = Convert(Varchar(20), DateAdd(minute, @Minutes, GetUTCDate()))
select @currentdate
0
 
LVL 48

Accepted Solution

by:
PortletPaul earned 250 total points
ID: 39183067
not sure why you are using convert(varchar...) at all here
conversion to varchar isn't required when setting a datetime by DATEADD
Returns a new datetime value based on adding an interval to the specified date.
try this:

Declare @Minutes numeric(10,2)
Declare @CurrentDate DateTime
SET @Minutes = DATEDIFF(minute, GetUTCDate(), GetDate())
SET @CurrentDate = DateAdd(minute, @Minutes, GetUTCDate())

select @currentdate, getdate(), GetUTCDate(), @Minutes


also note datediff isn't going to return 2 decimals either
DATEDIFF produces an error if the result is out of range for integer values.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question