Link to home
Start Free TrialLog in
Avatar of amillyard
amillyardFlag for United Kingdom of Great Britain and Northern Ireland

asked on

date / time management - c#, asp.net 2.x, iis 6.0, vs studio pro

The issues of timezones has crept into my programming requirements as server sits in a different timezone compared to users for example.  As a result, when posting record updates or anything relating to date and time, these are out of sync.

I am using the following script for example to gather to current date:

Label_Date.Text = DateTime.Now.ToString("ddd, MMM dd, yyyy");

I suspect this is gathering the date locally - if so, how do I collect the current date and time from the server?  (so then can sync up to the correct date/time zone locally depending on users location etc).

How are daylight saving worked out (in terms of keeping this uptodate and current, and in particular during that day of changing the clock back ro forward -- how you account for a loss or gain of an hour for example in the server logs/online form processing etc) -- as different countries have varying approaches to this.

The main thing I would like to resolve firstly, is gathering the latest date/time from the server (not via local o/s).

Thank you in advance for your time and efforts with this enquiry.
Avatar of Solar_Flare
Solar_Flare

if network traffic is not an issue and the clients are always online you could expose a simple web service on your server that has a GetCurrentTime function that provides the server's time - the clients could then ask for the servers time when needed.

alternatively if you rely on the time on the clients always being configured correctly you could use universal time for everything
Dim now As DateTime = DateTime.Now
Dim nowGMT As DateTime = now.ToUniversalTime()

Open in new window

Avatar of amillyard

ASKER

Solar_Flare:

I see -- do you have the equivalent as c# coding?
ASKER CERTIFIED SOLUTION
Avatar of Solar_Flare
Solar_Flare

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I am trying to update the @DateTimeStamp table column via a stored procedure -- @DateTimeStamp is structured as a smalldatetime variable.

When processing the update, this column is not changing it details.

is the attached code snippet correct?
DateTime now = DateTime.Now;
DateTime nowGMT = now.ToUniversalTime();
scCommand.Parameters.AddWithValue("@DateTimeStamp", nowGMT);

Open in new window

found the error - me ! ... looking at the wrong table (for the results)

thank you for your contribution.

I will award you the points for pointing me in the right direction -- but if you have to had an example of the web service for accessing server time (c#) would be much apprieated also.
you would just add a .asmx web service file to you web application and it would contain a webmethod. You would then add a web reference to your project pointing to the web service and then you can call it to ask the server for its current time.

in asmx file
[WebMethod]
public DateTime GetServerTime()
{
   return DateTime.Now;
}



in your application
webservicename service = new webservicename();
DateTime serverTime = service.GetServerTime();
Solar_Flare:

thank you for the above scripting...I am trying to add the web reference.  the problem seems to be that this project is secured (asp username/pw) and keep being returned to login page.  even when entering the correct un/pw, -- can invoke web post for util -- the web reference window is not allowing the web reference to be created.  (below is the error message in this window).

how do I get around this login issue (apart from taking security off?

do these files need to be in an open folder (no access/user retrictions)? -- i.e. available to anyone publically as well?
_____________________________________________

There was an error downloading 'http://localhost:3752/datetimeserver.asmx?op=GetServerTime'.

The request failed with the error message:
--
<html><head><title>Object moved</title></head><body>
<h2>Object moved to <a href="/login.aspx?ReturnUrl=%2fdatetimeserver.asmx%3fop%3dGetServerTime&op=GetServerTime">here</a>.</h2>
</body></html>

-
Web References :  datetimeServerUS

.cs scripting:

datetimeServerUS service = new datetimeServerUS();
DateTime serverTime = service.GetServerTime();

I am getting the following error:

'FORTUNE.datetimeServerUS' is a 'namespace' but is used like a 'type'
it ok, I got it to work 100%

again, many thanks :-)
I need to ask one more thing please, relating to the security of that web service -- as I had to remove security (i.e. asp.net un/pw) -- is there another way of security this service?

many thanks.