Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

how to get datetime from my server?

Posted on 2011-02-28
5
Medium Priority
?
544 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 200 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 1200 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 400 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 200 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 400 total points
ID: 35005483
0

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Suggested Courses

916 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