Solved

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

Posted on 2007-11-18
10
980 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
[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
  • 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
Guide to Performance: Optimization & Monitoring

Nowadays, monitoring is a mixture of tools, systems, and codes—making it a very complex process. And with this complexity, comes variables for failure. Get DZone’s new Guide to Performance to learn how to proactively find these variables and solve them before a disruption occurs.

 

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
 
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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Suggested Solutions

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

737 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