Solved

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

Posted on 2007-11-18
10
977 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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 

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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Flash (http://en.wikipedia.org/wiki/Adobe_Flash) has evolved over the years to where it has become a masterful tool for displaying content screen.  It has excellent layout placement, UI precision as well as rendering capabilities. This, along with t…
Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

776 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