I'm trying to store full value of current day's datetimeticks to a bigint SQL Datatype as Session ID. But couldn't possibly convert datatype(s) successfully.
My objective is to get current Datetime.Ticks in C# and store it as SessionId in SQL Server.(version 2008 R2)
In SQL Server, I declared SessionId as bigint as follows:
[Session_Id] [bigint] NOT NULL
In C# (Winform), I currently use this(working fine):
long sessionId;
sessionId = Convert.ToInt64((long)BigInteger.Divide(DateTime.Now.Ticks,(BigInteger)5445654850112.1245));
I tried to use without truncating values from BigInteger as below but it throws error.
BigInteger sessionId = DateTime.Now.Ticks;
The error of snapshot I get when I use the above code is:
I also tried convert to Int64 as below but the same error persists.
BigInteger sessionId = Convert.ToInt64(DateTime.Now.Ticks);
As per MSDN sources, size of BIGINT in SQL Server is 8 bytes
-2^63 (-9,223,372,036,854,775,808) to 2^63-1 (9,223,372,036,854,775,807)
And BigInteger in C# (System.Numerics) has no upper or lower bounds
Please provide alteative suggestions/fix for this error as my aim is to store full datetimeticks as SessionId
