I need to calculate the time a user spends on site. It is difference between logout time and login time to give me something like "Mr X spent 4 hours and 43 minutes online". So to store the4 hours and 43 minutes i declared it like this: duration
time NOT NULL
Is this valid or a better way to store this? I need to store in the DB because I have other calculations I need to use this for + other use cases.
The xs:duration data type represents a duration of time that is expressed by the Gregorian year, month, day, hour, minute, and second components. Derived from data type xdt:anyAtomicType. The range that can be represented by this data type is from -P83333333333333Y3M11574074074DT1H46M39.
The DATETIME type is used for values that contain both date and time parts. MySQL retrieves and displays DATETIME values in ' YYYY-MM-DD hh:mm:ss ' format. The supported range is '1000-01-01 00:00:00' to '9999-12-31 23:59:59' . The TIMESTAMP data type is used for values that contain both date and time parts.
The best data type would be DATETIME.
SQL Server accepts datetime values in ISO 8601 and ANSI formats, which are: yyyy-mm-ddThh:mm:ss. nnnnnn and yyyy-mm-dd hh:mm:ss. nnnnnn, respectively.
Storing it as an integer number of seconds will be the best way to go.
UPDATE
will be clean and simple - i.e. duration = duration + $increment
TIME
field - e.g. "TIME
values may range from '-838:59:59'
to '838:59:59'
"If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With