{"name":"dateToNumber","title":"dateToNumber","type":"command","url":"https://community.bistudio.com/wiki/dateToNumber","revid":378087,"updated":"2026-02-12T17:31:59Z","groups":["Environment"],"status":"ok","games":{"arma2":"1.00","arma2oa":"1.50","tkoh":"1.00","arma3":"0.50"},"since":"arma2 1.00","arma3_since":"0.50","description":"Convert a date to a float number, based on Jan 1st 00:00:00 = 0 and Dec 31st 23:59:59 = 1.\nThe same day and time in leap year will be different after 28th of February and 23:59 on 31st of December will be 1.00274.\n\nThis is how this command works. The 365 days of the year are presented in range 0..1. So each day will be:\n\n```sqf\n1 / 365 = 0.00273973\n```\n\nIn a leap year there are 366 days, so the range will increase by 1 day:\n\n```sqf\n1 / 365 * 366 = 1.00274\n```\n\nIn short, in a normal year the command returns in range 0...1 in a leap year it will return in range 0...1.00274.","syntaxes":[{"syntax":"dateToNumber date","params":[{"name":"date","type":"Date","type_expr":"Date"}],"returns":{"type":"Number","type_expr":"Number"},"form":"unary","right":{"text":"date"}}],"examples":[{"code":["_float = dateToNumber [2035, 7, 6, 12, 0]; // 0.510959"]},{"code":["dateToNumber date; // returns float number for the current date"]},{"text":"Calculate days from 1/1/1970:\n\n```sqf\n_fnc_daysFromEpoch =\n{\n    private _year = param [0];\n    private _days = 0;\n    for \"_i\" from 1970 to _year - 1 do\n    {\n        _days = _days + round linearConversion [0, 1, dateToNumber [_i, 12, 31, 23, 59], 0, 365, false];\n    };\n\n    _days + linearConversion [0, 1, dateToNumber _this, 0, 365, false];\n};\n\nhint str (date call _fnc_daysFromEpoch);\n```","code":["_fnc_daysFromEpoch =\n{\n\tprivate _year = param [0];\n\tprivate _days = 0;\n\tfor \"_i\" from 1970 to _year - 1 do\n\t{\n\t\t_days = _days + round linearConversion [0, 1, dateToNumber [_i, 12, 31, 23, 59], 0, 365, false];\n\t};\n\n\t_days + linearConversion [0, 1, dateToNumber _this, 0, 365, false];\n};\n\nhint str (date call _fnc_daysFromEpoch);"]}],"see_also":["date","dayTime","time","numberToDate"]}