Solved

How to use client date rather than server date

Posted on 2011-02-25
6
431 Views
Last Modified: 2012-05-11
Hi,

I have a web application written using vb.net.

There are a number of stored procedures that include date field parameters. These are passed in using the SqlDbType.DateTime datatype via a SQLParameter. This works fine.

My issue is that I use the Now() function in the aspx.vb code behind files to retrieve the current date/time which is then passed to the stored procedure.

This works fine when testing on my development machine but when using the site via the web host (based in USA) I am getting the US date/time stored in the database which is 6 hours different.

Does anyone know a solution so that I can use the client datetime and set the sqlparameter using this via the code behind files.

Thanks in advance,

Dave
0
Comment
Question by:daveswarbrick
6 Comments
 
LVL 14

Expert Comment

by:quizwedge
ID: 34978155
I've got two suggestions that could work.

The first is to to just use Date.Now.AddHours(TimeZoneOffset). Store TimeZoneOffset somewhere you can access it across the site. That way if you ever move hosts, you only have to change the variable once.

The second way is to use getdate() in your SQL. This would have SQL get the date rather than the web host.
0
 
LVL 14

Expert Comment

by:robasta
ID: 34978172
>remember, client's data should not be trusted, (some dates on clients computers will not be accurate: what happens when users' date is in the future, or if it is still in the 90s?)

I suggest you use the server time, but add an offset based on your actual timezone ( DateTimeOffset).

see here: http://msdn.microsoft.com/en-us/library/bb384267.aspx
0
 
LVL 1

Author Comment

by:daveswarbrick
ID: 34978257
Could you please provide a code example to replace;

DateAuthorised = Now()

which will add 6 hours to the time returned above.

Also, is there a way to make the offset changed based on daylight saving, ie, the putting the clock's forward and back?

Thanks,

Dave



0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 14

Accepted Solution

by:
robasta earned 500 total points
ID: 34978290
0
 
LVL 1

Author Closing Comment

by:daveswarbrick
ID: 34978758
Thanks robasta!

Now using a function to return the UTC rather than using Now()
0
 
LVL 8

Expert Comment

by:Anurag Agarwal
ID: 34978836
Dave if u r sure with the time difference that it is  6hrs (may be +6 hrs or -6hrs ) you can simply add or subtract to the server time for eg

   Dim DateAuthorised As DateTime = Now()
        DateAuthorised.AddHours(+6)
        'subtract hrs
        DateAuthorised.AddHours(-6)

        'if some minutes are also
        DateAuthorised.AddMinutes(+30)
        DateAuthorised.AddMinutes(-30)


this may solve the problem but be sure that how you manage the difference of time.
0

Featured Post

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

Learn by example how to specify CSS selectors for Selenium WebDriver test automation software.
An enjoyable and seamless user experience can go a long way on an eCommerce site. While a cohesive layout and engaging copy play roles in creating a positive user experience, some sites neglect aspects that seem marginal but in actuality prove very …
Learn how to set-up custom confirmation messages to users who complete your Wufoo form. Include inputs from fields in your form, webpage redirects, and more with Wufoo’s confirmation options.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

861 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now