Click here to Skip to main content
15,895,740 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
My Winform application run on the client machine and it will interact with the Sql server database on the Server

All through my application developement i had foolisingly used Datetime.Now to get the date and time of entries to queries ,tracking etc

But i know that the user can miss use it like making a dataentry on 23 march with the system date set to 23rd of february and claiming he had already done his work


So what I want is a better solution to synchronise with the database datetime .I had already done it with comparing the system time with the getdata() value of the Server at application start and within fixed interval but then also there is a chance of changing time within the defined intervals
can anyone suggest better idea ?
Posted

1 solution

Do it at the Server instead: SQL supports the GetDate method:

SQL
INSERT INTO myTable (UserID, entryTimeStamp) VALUES('12345', GETDATE())
 
Share this answer
 
Comments
SREENATH GANGA 19-Mar-13 3:43am    
@orginal grif you mean to say that i have to change all the insert query and replace all system.datetime.now.date to getdate() or any other a tips at server end
OriginalGriff 19-Mar-13 4:07am    
Yes - change them all so they use GETDATE and that way teh date is always read and kept in Serevr time rather than Client. They can't "cheat" and as a single time source is used it is much safer for comparisons.
SREENATH GANGA 19-Mar-13 5:06am    
I am doing the same but the issue still remain why cannot we tell the application not to run unless the both the server time and client time are not synchroonized
OriginalGriff 19-Mar-13 5:29am    
How far out should you accept? 30 seconds? A minute? An hour? Who set the time and time zone originally on your SQL server? Are they correct? Is the SQL server currently and always going to be in the same time zone as the client? If you always use the server as the time source, it doesn't matter what the client does - your data is always stored with a consistent value.

You could make them synchronise - just issue a SELECT GETDATE() statement to find out the server time - and then subtract the two DateTime values. If that is within your permitted difference, then continue, but to be sure there was no "cheating" going on, you would have to do that every time you inserted or updated the database - and if an application nagged at me to change my date and / or time, I would get pretty annoyed with it! :laugh:

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