Solved

how to get datetime from my server?

Posted on 2011-02-28
5
529 Views
Last Modified: 2013-12-17
hi,

I am developing a client application which will be running on PC connected in the network (LAN), I want to get the date stored in my server,

suppose my server ip is: 192.168.x.x, how can I get the date of my server?
0
Comment
Question by:njgroup
[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
5 Comments
 
LVL 10

Assisted Solution

by:Asim Nazir
Asim Nazir earned 50 total points
ID: 35004586
Hi,

If your application server is running on that machine then you can simply expose a WCF or web service returning server date using DateTime.Now.

Is your application server running on that server?

Asim
0
 
LVL 53

Accepted Solution

by:
Dhaest earned 300 total points
ID: 35004590
How to get current date in SQL Server
http://www.dotnetspider.com/resources/6416-How-get-current-date-SQL-Server.aspx
http://blog.sqlauthority.com/2008/08/01/sql-server-2008-get-current-system-date-time/
http://www.blackwasp.co.uk/SQLGetDate.aspx
SqlClient.SqlConnection conn = new SqlClient.SqlConnection("Server=***;Database=***;Trusted_Connection=True;"); 

 SqlClient.SqlCommand cmd = new SqlClient.SqlCommand("SELECT getdate()",conn); 

 conn.Open(); 
 System.DateTime d = System.DateTime.Parse(cmd.ExecuteScalar); 
 conn.Close();

Open in new window

0
 
LVL 9

Assisted Solution

by:mayank_joshi
mayank_joshi earned 100 total points
ID: 35004872
get the Coordinated Universal Time (UTC) and add or subtract server's  time zone offset  from it. Hopefully, server's  time zone offset would be constant.
UTC is the same for all locations.

For example, if I know server's time zone offset is UTC - 4 hrs 30 mins  then I can simply subtract  4 hrs 30 mins to get the local time of server.

DateTime currentTime = DateTime.UtcNow; 

DateTime serverTime=currentTime.AddHours(-5).AddMinutes(-30);

Open in new window


the following article might be helpful:-

http://www.4guysfromrolla.com/articles/081507-1.aspx

Open in new window


0
 
LVL 5

Assisted Solution

by:andr_gin
andr_gin earned 50 total points
ID: 35005159
1.) It is a LAN, so I do not think the server will be in a different time zone ;-)

2.) I think the point is that you cannot run code on the server itself, but want to know which time is set on the server (maybe for time synchronization???)

3.) I dont know I way by only knowing the IP address, but some services return datetime in one of the headers. For example if you have a webserver and send him a request (in this case the google server) your response will look like this:

HTTP/1.1 200 OK
Date: Tue, 01 Mar 2011 09:12:59 GMT
Expires: -1
Cache-Control: private, max-age=0
Content-Type: text/html; charset=UTF-8
Content-Encoding: gzip
Server: gws
Content-Length: 5866
X-XSS-Protection: 1; mode=block

The seconds line is the date. You can Parse it, create a new DateTime and execute convert it to local date with ServerDate.ToLocalTime
0
 
LVL 9

Assisted Solution

by:mayank_joshi
mayank_joshi earned 100 total points
ID: 35005483
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
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…

738 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