Solved

how to get datetime from my server?

Posted on 2011-02-28
5
525 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
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: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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

Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

820 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