Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Handling GMT date issue to enable/disable button

Posted on 2013-05-20
3
Medium Priority
?
450 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 750 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 49

Accepted Solution

by:
PortletPaul earned 750 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

Industry Leaders: 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

For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Windocks is an independent port of Docker's open source to Windows.   This article introduces the use of SQL Server in containers, with integrated support of SQL Server database cloning.
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

715 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