Difference between revisions of "TIniFile.ReadDateTime"

From Soldat Community Wiki
Jump to: navigation, search
(new page)
 
m
 
Line 10: Line 10:
 
If it fails to do so for some reason, the ''Default'' value is returned.<br>
 
If it fails to do so for some reason, the ''Default'' value is returned.<br>
 
This function is very similar to [[TIniFile.ReadDate|ReadDate]], however, it includes an hour.<br>
 
This function is very similar to [[TIniFile.ReadDate|ReadDate]], however, it includes an hour.<br>
'''Important''': Result is a number of days that have passed since 1899-12-30 till date under the key in the ini file. Because of that, it's probably a good idea to use [[TIniFile.ReadString|ReadString]] to read a clarified date.
+
'''Important''': Result is a number of days that have passed since 1899-12-30 till date under the key in the ini file.  
 +
Because of that, it's probably a good idea to use [[TIniFile.ReadString|ReadString]] to read a clarified date.
 +
You could also encode it using one of the available [[:Category:Functions|Functions]]
  
 
==Example==
 
==Example==

Latest revision as of 18:54, 22 August 2013

function ReadDateTime(const Section, Ident: string; Default: TDateTime): TDateTime
 Section: Section name
 Ident: Property name (key)
 Default: Value used as a result when the key has not been found
 Result: Value of a key (if successful) or Default (if not)

Description

This function will try to read a TDateTime value from specified section and key
If it fails to do so for some reason, the Default value is returned.
This function is very similar to ReadDate, however, it includes an hour.

Important: Result is a number of days that have passed since 1899-12-30 till date under the key in the ini file. 
Because of that, it's probably a good idea to use ReadString to read a clarified date.
You could also encode it using one of the available Functions

Example

example.ini in soldatserver's root folder

[ModConfig]
Date1=2013-08-21
Date2=2013-08-21 12:00:00
Date3=2013-08-21 13:48:00

script code:

const
  // assuming Sandboxed Level < 2
  PATH = 'example.ini';
var
  Ini: TIniFile;
  temp: TDateTime; // could as well be  temp: Double;

begin
  Ini := File.CreateINI(PATH);
  temp := Ini.ReadDateTime('ModConfig','Date1',0); // temp = 41507.0
  temp := Ini.ReadDateTime('ModConfig','Date2',0); // temp = 41507.5
  temp := Ini.ReadDateTime('ModConfig','Date3',0); // temp = 41507.575
  Ini.Free;
end.