Last post Dec 19, 2014 03:09 PM by anas
Dec 19, 2014 11:52 AM|vishnu.vg1984|LINK
A scenario to develop a transaction system to store records of different timezone users. It need to delete the records at 12am midnight of the respective time zones. For eg: User for India has two transactions , user from USA has 4 transactions, and all
those should delete at 12am midnight(of the respective countries).
One way to solve is to write a service to run in aparticular frequency in server to delete the transactions, but I am not getting the logic on how to find and delete the transactions of that respective countries midnight. Anyone has any idea, please help.
Dec 19, 2014 03:09 PM|anas|LINK
If you are linking between the country and the user transacations, then it think it's easy.
You can check every few minutes the following:
Calculate India time simply by DateTime.Now.AddHours( hours difference between india timezone and server timezone).
if it's 12 AM, you delete the transactions for India users.
Calculate USA time (Similar to above)
if it's 12 AM in USA, you delete USA users transactions.
You can store the hours offeset in your countries database table by adding a new column for it.
Another solution for getting the time for specific country is via the
TimeZone class , here is an example:
TimeZoneInfo indiaTime = TimeZoneInfo.FindSystemTimeZoneById("India Standard Time");
To get all the possible timezone IDs which are passed to this previous function, you use the TimeZoneInfo.GetSystemTimeZones
foreach (TimeZoneInfo timeZone in TimeZoneInfo.GetSystemTimeZones())