Loading...
Searching...
No Matches
datetime Type Reference

Definition

Compact representation of date and time Stores all components in minimal integer kinds to reduce memory usage. All fields are public for easy access.

Constructor interface for datetime type.

Examples

type(datetime) :: bt
bt = datetime('2025-08-12 09:30:00')
print *, 'build on: ', bt%to_string('ddd-MMM-yyyy')
...

Remarks

The date implementation proposed here is kept at the bare minimum of what is required by the library. There are many other implementations that can be found.

Constructors

Initializes a new instance of the datetime class

datetime(character(*), character(*))

type(datetime) function datetime(character(*) string, (optional) character(*) fmt) 
Parameters
[in]stringdate as string
[in]fmt(optional) date format

Examples

type(datetime) :: d
d = datetime('2025-08-12 09:30:00')

datetime(integer, integer, integer, integer, integer, integer, integer)

type(datetime) function datetime((optional) integer year, (optional) integer month, ...) 
Parameters
[in]year(optional)
[in]month(optional)
[in]day(optional)
[in]hour(optional)
[in]minute(optional)
[in]second(optional)
[in]millisecond(optional)

Examples

type(datetime) :: d
d = datetime(1970, 1, 1)
Returns
The constructed datetime object.

Remarks

Remarks

Definition at line 118 of file date.f90.


The documentation for this type was generated from the following file:

Variables

integer(i2), public year
 Year.
 
integer(i1), public month
 Month.
 
integer(i1), public day
 Day.
 
integer(i1), public hour
 Hour.
 
integer(i1), public minute
 Minute.
 
integer(i1), public second
 Second.
 
integer(i2), public millisecond
 Millisecond.
 

Methods

◆ parse()

procedure, pass, public parse ( class(datetime), intent(inout) this,
character(*), intent(in) string,
character(*), intent(in), optional fmt )

Parse date/time from string using common formats.

Supports ISO, US, and abbreviated month formats. On error, defaults to Unix epoch (1970-01-01 00:00:00) Perform conversion to ISO string

  • d: Represents the day of the month as a number from 1 through 31.
  • dd: Represents the day of the month as a number from 01 through 31.
  • ddd: Represents the abbreviated name of the day (Mon, Tues, Wed, etc).
  • dddd: Represents the full name of the day (Monday, Tuesday, etc).
  • h: 12-hour clock hour (e.g. 4).
  • hh: 12-hour clock, with a leading 0 (e.g. 06)
  • H: 24-hour clock hour (e.g. 15)
  • HH: 24-hour clock hour, with a leading 0 (e.g. 22)
  • m: Minutes
  • mm: Minutes with a leading zero
  • M: Month number(eg.3)
  • MM: Month number with leading zero(eg.04)
  • MMM: Abbreviated Month Name (e.g. Dec)
  • MMMM: Full month name (e.g. December)
  • s: Seconds
  • ss: Seconds with leading zero
  • t: Abbreviated AM / PM (e.g. A or P)
  • tt: AM / PM (e.g. AM or PM
  • y: Year, no leading zero (e.g. 2015 would be 15)
  • yy: Year, leading zero (e.g. 2015 would be 015)
  • yyy: Year, (e.g. 2015)
  • yyyy: Year, (e.g. 2015)

Remarks

Definition at line 111 of file date.f90.

◆ to_string()

procedure, pass, public to_string ( class(datetime), intent(in) this,
character(*), intent(in), optional fmt )

Format datetime as string using flexible format codes Supports many common patterns including those required for __DATE__ and __TIMESTAMP__. Default format: 'yyyy-MM-ddTHH:mm:ss'.

Remarks

Definition at line 110 of file date.f90.