dateToNumber: Difference between revisions

From Bohemia Interactive Community
Jump to navigation Jump to search
m (Text replacement - "\| *((\[\[[a-zA-Z0-9_ |()]+\]\],? ?)+) * \}\}" to "|seealso= $1 }}")
m (Some wiki formatting)
 
(40 intermediate revisions by the same user not shown)
Line 1: Line 1:
{{RV|type=command
{{RV|type=command


| arma2
|game1= arma2
|version1= 1.00


|1.00
|game2= arma2oa
|version2= 1.50
 
|game3= tkoh
|version3= 1.00
 
|game4= arma3
|version4= 0.50


|gr1= Environment
|gr1= Environment


| Convert a date to a float number, based on Jan 1st 00:00:00 <nowiki>=</nowiki> 0 and Dec 31st  23:59:59 <nowiki>=</nowiki> 1. The 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 <br><br>
|descr= Convert a date to a float number, based on Jan 1st 00:00:00 = 0 and Dec 31st  23:59:59 = 1. The 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.<br><br>
This is how this command works. The 365 days of the year are presented in range 0...1. So each day will be:<br>
This is how this command works. The 365 days of the year are presented in range 0...1. So each day will be:
<tt>1 / 365 <nowiki>=</nowiki>  0.00273973</tt> <br>
<sqf>1 / 365 = 0.00273973</sqf>
In a leap year there are 366 days, so the range will increase by 1 day:<br>
In a leap year there are 366 days, so the range will increase by 1 day:
<tt>1 / 365 * 366 <nowiki>=</nowiki> 1.00274</tt><br>
<sqf>1 / 365 * 366 = 1.00274</sqf>
In short, in a normal year the command returns in range 0...1 in a leap year it will return in range 0...1.00274
In short, in a normal year the command returns in range 0...1 in a leap year it will return in range 0...1.00274.


| '''dateToNumber''' date
|s1= [[dateToNumber]] date


|p1= date: [[Array]] - array in [[date]] format
|p1= date: [[Array]] - array in [[date]] format


| [[Number]]
|r1= [[Number]]


|x1= <code>_float = [[dateToNumber]] [2035,7,6,12,0]; //0.510959</code>
|x1= <sqf>_float = dateToNumber [2035,7,6,12,0]; // 0.510959</sqf>


|x2= <code>[[dateToNumber]] [[date]]; //will return float number for the current date.</code>
|x2= <sqf>dateToNumber date; // returns float number for the current date</sqf>


|x3= Calculate days from 1/1/1970: <code>fnc_daysFromEpoc =  
|x3= Calculate days from 1/1/1970:
<sqf>
fnc_daysFromEpoc =  
{
{
[[private]] _year = [[param]] [0];
private _year = param [0];
[[private]] _days = 0;
private _days = 0;
[[for]] "_i" [[from]] 1970 [[to]] _year - 1 [[do]]
for "_i" from 1970 to _year - 1 do  
{
{
_days = _days + [[round]] [[linearConversion]] [0, 1, [[dateToNumber]] [_i, 12, 31, 23, 59], 0, 365, [[false]]];
_days = _days + round linearConversion [0, 1, dateToNumber [_i, 12, 31, 23, 59], 0, 365, false];
};
};
_days + [[linearConversion]] [0, 1, [[dateToNumber]] _this, 0, 365, [[false]]];
_days + linearConversion [0, 1, dateToNumber _this, 0, 365, false];
};
};


[[hint]] [[str]] ([[date]] [[call]] fnc_daysFromEpoc);</code>
hint str (date call fnc_daysFromEpoc);
</sqf>


|seealso= [[date]], [[daytime]], [[time]], [[numberToDate]]
|seealso= [[date]] [[dayTime]] [[time]] [[numberToDate]]
}}
}}
{{GameCategory|arma2|Scripting Commands}}
{{GameCategory|arma3|Scripting Commands}}
{{GameCategory|tkoh|Scripting Commands}}
[[Category:Scripting Commands|{{uc:{{PAGENAME}}}}]]

Latest revision as of 13:12, 13 May 2022

Hover & click on the images for description

Description

Description:
Convert a date to a float number, based on Jan 1st 00:00:00 = 0 and Dec 31st 23:59:59 = 1. The 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.

This is how this command works. The 365 days of the year are presented in range 0...1. So each day will be:
1 / 365 = 0.00273973
In a leap year there are 366 days, so the range will increase by 1 day:
1 / 365 * 366 = 1.00274
In short, in a normal year the command returns in range 0...1 in a leap year it will return in range 0...1.00274.
Groups:
Environment

Syntax

Syntax:
dateToNumber date
Parameters:
date: Array - array in date format
Return Value:
Number

Examples

Example 1:
_float = dateToNumber [2035,7,6,12,0]; // 0.510959
Example 2:
dateToNumber date; // returns float number for the current date
Example 3:
Calculate days from 1/1/1970:
fnc_daysFromEpoc = { private _year = param [0]; private _days = 0; for "_i" from 1970 to _year - 1 do { _days = _days + round linearConversion [0, 1, dateToNumber [_i, 12, 31, 23, 59], 0, 365, false]; }; _days + linearConversion [0, 1, dateToNumber _this, 0, 365, false]; }; hint str (date call fnc_daysFromEpoc);

Additional Information

See also:
date dayTime time numberToDate

Notes

Report bugs on the Feedback Tracker and/or discuss them on the Arma Discord or on the Forums.
Only post proven facts here! Add Note