# How to Convert CTime to Dates

- 1). Divide the CTime variable, called "N" from this point onwards, by 86400 in order to calculate the number of days. Round it down to the nearest whole number and write it down. This number will be "TD" from this point onwards. Calculate (N - TD * 86400) and write it down. This number will be "RS" from this point onwards.

For example, if N = 4956352625, then TD = 57365 and RS = 16625. - 2). Divide TD by 365 and round it down to the nearest whole number. Call the result "TY" and write it down. Calculate (TD - TY * 365), call the result "RD" and write it down. Divide TY by four, round it down to the nearest whole number, call the result "RLY" and write it down. If RLY is greater than RD, decrease TY by one and increase RD by 365. If RLY is still greater than RD repeat the process of decreasing TY by one and increasing RD by 365 until RLY is lower than or equal to RD.

For example, if TD = 57365, then TY = 157, RD = 60 and RLY = 39. - 3). Calculate (1970 + TY), call it "Y" and write it down. Divide (Y - 1) by four, round it down to the nearest whole number and multiply the result by four. Call the result "CLY" -- this is the last leap year to have completely passed before Y.

For example, if TY = 157, then Y = 2127 and CLY = 2124. - 4). Calculate (CLY - 1972), divide it by four and add one, call the result "TLY" and write it down. TLY should be a whole number that differs from RLY by no more than one; most of the time, TLY and RLY will be identical. If these two numbers differ by more than one, you have made a mistake; repeat the process from step one.

For example, if CLY = 2124, then TLY = 39. - 5). Divide CLY by 100 and round it down to the nearest whole number. Call the result "TC" and write it down. If TC is equal to 19, define a new variable called "NS" as equal to zero.

Otherwise, subtract 20 from TC, call it "NTC" and write it down. Divide NTC by four and round it down to the nearest whole number. Call the result "NTCR" and write it down. Subtract NTCR from NTC, call the result "NS" and write it down. The purpose of this calculation is to determine the amount of years between 1972 and CLY whose numbers were divisible by four that weren't leap years: in the Gregorian calendar, those are the years that are wholly divisible by 100 but not by 400, such as the years 2100, 2200, 2300, 2500 and so on.

For example, if CLY = 2124, then TC = 21, NTC = 1, NTCR = 0 and NS = 1. - 6). Calculate (TLY - NS), call the result "LY" and write it down.

For example, if TLY = 39 and NS = 1, then LY = 38. - 7). Calculate (RD - LY), call the result "CD" and write it down.

For example, if RD = 60 and LY = 38, then CD = 22. - 8). Determine whether Y is a leap year by checking whether it is wholly divisible by four. If it isn't, it is not a leap year. If it is, it is a leap year unless it is also wholly divisible by 100 and not wholly divisible by 400.

If CD is greater than or equal to 366 and Y is a leap year, increase Y by one and decrease CD by 366; if Y is not a leap year, increase Y by one and decrease CD by 365. If CD is still greater than or equal to 366 repeat this process until it becomes lower than 366.

If CD is now equal to 365 and Y is not a leap year, increase Y by one and decrease CD by 365. If Y is a leap year both CD and Y remain unchanged.

If CD is now lower than 365 both CD and Y remain unchanged.

For example, if Y = 2127 and CD = 22, they both remain unchanged. - 9). Calculate the month using the following method. First, if the value of Y has changed determine whether the new Y is a leap year or not using the calculation described in step eight.

If Y is not a leap year, use the following method.

If CD is greater than or equal to zero, but lower than 31, then "M" is "January" and "D" is equal to (CD + 1).

If CD is greater than or equal to 31, but lower than 59, then "M" is "February" and "D" is equal to (CD - 30).

If CD is greater than or equal to 59, but lower than 90, then "M" is "March" and "D" is equal to (CD - 58).

If CD is greater than or equal to 90, but lower than 120, then "M" is "April" and "D" is equal to (CD - 89).

If CD is greater than or equal to 120, but lower than 151, then "M" is "May" and "D" is equal to (CD - 119).

If CD is greater than or equal to 151, but lower than 181, then "M" is "June" and "D" is equal to (CD - 150).

If CD is greater than or equal to 181, but lower than 212, then "M" is "July" and "D" is equal to (CD - 180).

If CD is greater than or equal to 212, but lower than 243, then "M" is "August" and "D" is equal to (CD - 211).

If CD is greater than or equal to 243, but lower than 273, then "M" is "September" and "D" is equal to (CD - 242).

If CD is greater than or equal to 273, but lower than 304, then "M" is "October" and "D" is equal to (CD - 272).

If CD is greater than or equal to 304, but lower than 334, then "M" is "November" and "D" is equal to (CD - 303).

If CD is greater than or equal to 334, but lower than 365, then "M" is "December" and "D" is equal to (CD - 333).

If Y is a leap year, use the following method.

If CD is greater than or equal to zero, but lower than 31, then "M" is "January" and "D" is equal to (CD + 1).

If CD is greater than or equal to 31, but lower than 60, then "M" is "February" and "D" is equal to (CD - 30).

If CD is greater than or equal to 60, but lower than 91, then "M" is "March" and "D" is equal to (CD - 59).

If CD is greater than or equal to 91, but lower than 121, then "M" is "April" and "D" is equal to (CD - 90).

If CD is greater than or equal to 121, but lower than 152, then "M" is "May" and "D" is equal to (CD - 120).

If CD is greater than or equal to 152, but lower than 182, then "M" is "June" and "D" is equal to (CD - 151).

If CD is greater than or equal to 182, but lower than 213, then "M" is "July" and "D" is equal to (CD - 181).

If CD is greater than or equal to 213, but lower than 244, then "M" is "August" and "D" is equal to (CD - 212).

If CD is greater than or equal to 244, but lower than 274, then "M" is "September" and "D" is equal to (CD - 243).

If CD is greater than or equal to 274, but lower than 305, then "M" is "October" and "D" is equal to (CD - 273).

If CD is greater than or equal to 305, but lower than 335, then "M" is "November" and "D" is equal to (CD - 304).

If CD is greater than or equal to 335, but lower than 366, then "M" is "December" and "D" is equal to (CD - 334).

For example, if Y = 2127 and CD = 22, then M is January and D = 23. - 10

Divide RS by 3600 and round it down to the nearest whole number. Call the result "H" and write it down. H should not be greater than 23. If it is, you have made a mistake; repeat the entire process from the start. Calculate (RS - H * 3600), call the result "RSH" and write it down.

For example, if RS = 16625, then H = 4 and RSH = 2225. - 11

Divide RSH by 60 and round it down to the nearest whole number. Call the result "M" and write it down. Calculate (RSH - M*60), call the result "S" and write it down.

For example, if RSH = 2225, then M = 37 and S = 5. - 12

Write the result as "H:M:S, D M Y." This is the date corresponding to your CTime value.

For example, if N = 4956352625, the result is "04:37:05, 23 January 2127."