0

I am in serious situation when developing a library management system, if someone return a book, there is a function to insert book details to database which takes system date as returned date, then comparing borrowed date and returned date I can calculate fine if any, but thing is by changing the system date to a previous date above current date anyone can return the book without effecting to the fine because it insert system date as current date and it changed now.

example :

think loan duration is 7 days then

borrow date is 11/05/2012

return date 20/05/2012 (think this is today and it get as a system date)

Now there is 2 days of delay (so there is a fine to calculate)

if I change system date to the previous date like 15/05/2012 then it take the system date as a changed date so there can be a book returning without calculating fine which must calculate the fine ?

Roledenez
  • 751
  • 4
  • 16
  • 43
  • You could host the server yourself in which case you can control the clock, but you do know the clerk could always just choose not to charge the customer anyway, whether the system says or not... – lc. Jul 25 '14 at 07:57
  • 3
    Will the end-user be able to change the date on the system and/or database server? – dwana Jul 25 '14 at 07:58
  • think CMOS battary is died ? then suddenly change the system date and illegal values are inserted to the database ? – Roledenez Jul 25 '14 at 16:30

3 Answers3

2

There is no way to do that programatically since you'll always get the date set on the pc where your system is running.

What you can do is get the current date from another pc/server or have administrator rights configured in that PC so nobody can change the system's time.

Check this for the first option: get ACTUAL date time and not system date time in C#

Community
  • 1
  • 1
Joanvo
  • 5,677
  • 2
  • 25
  • 35
0

You could setup your mysql database on another machine that is unavailable for changes by unauthorized people and then use mysql date/time functions.

Define your return table for example like this:

create table book_return (book_id int, return_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP);

then you could use that time for your calculations.

Read more about mysql date/time functions: http://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html

Also - if you MUST have mysql db + your app on one machine, you could try to obtain current time from NTP server, but that might be overkill;) How to Query an NTP Server using C#?

Community
  • 1
  • 1
ketonal
  • 1
  • 1
  • I did not use current date of database because if I change my database server (US to AUG) that server time also change ? – Roledenez Jul 25 '14 at 16:37
  • If you move your server from one timezone to another then of course server time would change few hours, but you can detect that and compensate. – ketonal Jul 28 '14 at 05:42
0

You must have the Database in a centralized system which must be a server for windows application or Web based.. so try using the Server time. Create default value for the column/field..

CREATE TABLE BookDetails (BookId int, ReturnedTime datetime DEFAULT getdate())

Jai
  • 269
  • 2
  • 4