Click here to Skip to main content
15,888,242 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi sir,

How can i get server datetime at the time of registration in my website using asp.net c#?
Posted

Example i written in my project

public static DateTime GetServerDateTime()
{


try
{
DateTime serverDateTime = new DateTime();
serverDateTime =select GETDATE(); //(This is your server date)
return serverDateTime;
}
catch (Exception ex)
{
throw ex;
}

}
 
Share this answer
 
v2
Comments
jaheena 16-Apr-11 4:08am    
hi sir,

serverDateTime =select GETDATE(); //(This is your server date)
This line don't understand plz more clear it
Sridhar Patnayak 16-Apr-11 5:51am    
In sqlserver if you write query like this

select GETDATE();

you will get current date
You take a label which you display time


NOw page load event you write:-
Label1.text=DateTime.Now.ToString()



In above code is display server datetime.
 
Share this answer
 
This article[^] should help you out.
 
Share this answer
 
Generally When We Place Application Folder In Server
It Takes Original Server Time Not Takes From Client System Time
So You Take The Time At Registration as DateTime dt = DateTime.Now
Thats It....
 
Share this answer
 
Comments
tulasiram3975 16-Apr-11 7:39am    
Oops I went more
connect to your sql database, open the connection, query for either one of these
SQL
SELECT CURRENT_TIMESTAMP
GO
SELECT {fn NOW()}
GO
SELECT GETDATE()
GO

you will get server time in result set.
Hope it serves your purpose.

Thanks
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900