Solved

how to get datetime from my server?

Posted on 2011-02-28
5
532 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

Command Line Tips and Tricks

The command line is a powerful tool at the disposal of every Linux user. Although Linux distros come with beautiful user interfaces, it's worthwhile to learn the command line because it allows you to do a number of things that you otherwise cannot do from the GUI.  

Question has a verified solution.

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

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

635 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