Solved

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

Posted on 2007-11-18
10
974 Views
Last Modified: 2013-12-17
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.
0
Comment
Question by:amillyard
  • 7
  • 3
10 Comments
 
LVL 15

Expert Comment

by:Solar_Flare
ID: 20309749
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

0
 

Author Comment

by:amillyard
ID: 20309757
Solar_Flare:

I see -- do you have the equivalent as c# coding?
0
 
LVL 15

Accepted Solution

by:
Solar_Flare earned 500 total points
ID: 20310394
you mean those 2 lines of VB?
DateTime now = DateTime.Now;

DateTime nowGMT = now.ToUniversalTime();

 

Open in new window

0
 

Author Comment

by:amillyard
ID: 20311271
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

0
 

Author Comment

by:amillyard
ID: 20311322
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.
0
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
LVL 15

Expert Comment

by:Solar_Flare
ID: 20314944
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();
0
 

Author Comment

by:amillyard
ID: 20316692
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>

-
0
 

Author Comment

by:amillyard
ID: 20316750
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'
0
 

Author Comment

by:amillyard
ID: 20316801
it ok, I got it to work 100%

again, many thanks :-)
0
 

Author Comment

by:amillyard
ID: 20316821
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.
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

It seems a simple enough task, yet I see repeated questions asking how to do it: how to pass data between two forms. In this article, I will show you the different mechanisms available for you to do just that. This article is directed towards the .N…
This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

746 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

13 Experts available now in Live!

Get 1:1 Help Now