datetime Mode

In datetime mode, datetime values are generated. The format of the command is as follows:

randog datetime [MINIMUM MAXIMUM] [--iso | --fmt FORMAT] [common-options]

Arguments and Options

  • MINIMUM (optional):

    • the minimum value; see also here. If not specified, the behavior is left to the specification of randdatetime.

  • MAXIMUM (optional):

    • the maximum value; see also here. If not specified, the behavior is left to the specification of randdatetime.

  • --iso (optional):

  • --fmt FORMAT (optional):

  • common-options

Expression of MINIMUM and MAXIMUM

You can specify the arguments MINIMUM and MAXIMUM with following expressions:

  • now: it means current datetime

  • ISO-8601 format, such as 2022-01-01T00:00:00.000000, 2022-01-01T00:00:00, or, 2022-01-01.

  • datetime combined with simple format of timedelta, such as now+2h, or, 2022-01-01-1h30m.

  • simple format of timedelta (datetime term is omitted), such as +2h:, or, -30m

    • If the other (MAXIMUM or MINIMUM) is specified with datetime term, it means the other plus the timedelta.

    • If the other (MAXIMUM or MINIMUM) is fully omitted or datetime term of the other is omitted, it means now plus the timedelta.

Note

A simple expression such as -30m can be used, but since it begins with -, it is interpreted as an optional argument and will cause an error. To avoid this, it must be specified after --, as in the following example.

# valid (example for usage with --repeat)
randog datetime --repeat 10 -- -30m +30m

# invalid (unknown option -30m)
randog datetime --repeat 10 -30m +30m

Examples

The simplest example is the following, which outputs a datetime value.

randog datetime

You can specify a range of values to be generated, as in the following example:

# generates a value between 2021-01-01T00:00:00 and 2021-01-01T12:00:00
randog datetime 2021-01-01 2021-01-01T12:00:00

# generates a value between yesterday and tomorrow
randog datetime -- -1d +1d

# generates a value between 7 days ago and now
randog datetime -- -7d

# generates a value between now and 1 hour later
randog datetime +1h

Note

See Expression of MINIMUM and MAXIMUM for expressions such as +1d.

Format: ISO-8601, etc.

By default, the output is in the standard python format, but you can change the output format to the format specified in the form of strftime or strptime or ISO-8601 format by specifying options as follows:

# generates a value with ISO-8601 format
randog datetime --iso

# generates a value with the specified format
randog datetime --fmt '%Y/%m/%d %H:%M'

Repeatedly Generate

Most likely, you will not be satisfied with just one generated, so you will probably want to output multiple times as follows:

# Repeat 10 times
randog datetime -r 10

# Generate list which contains 10 values
randog datetime -L 10 --json --fmt '%Y/%m/%d %H:%M'

Note

In datetime mode, date and time are generated simultaneously. If only one is wanted, use date mode or time mode.

Also, if you want to generate an elapsed time rather than a time that points to a certain point in time, use timedelta mode.