Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

How to use client date rather than server date

Posted on 2011-02-25
6
Medium Priority
?
437 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
[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
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 14

Accepted Solution

by:
robasta earned 2000 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

Simplify Your Workload with One Tool

How do you combat today’s intelligent hacker while managing multiple domains and platforms? By simplifying your workload with one tool. With Lunarpages hosting through Plesk Onyx, you can:

Automate SSL generation and installation with two clicks
Experience total server control

Question has a verified solution.

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

When it comes to write a Context Sensitive Help (an online help that is obtained from a specific point in state of software to provide help with that state) ,  first we need to make the file that contains all topics, which are given exclusive IDs. …
Australian government abolished Visa 457 earlier this April and this article describes how this decision might affect Australian IT scene and IT experts.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to count occurrences of each item in an array.

618 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