Solved

how to get datetime from my server?

Posted on 2011-02-28
5
517 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

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.
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

771 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now