Python command: HSI Date

The hsidate commands in Python allow you to access and format date and time information. See Python commands for other commands you can use with GainSeeker.

Note: The "DB format" expression below refers to the 16-character date/time strings that are stored in the GainSeeker database.

The format of these strings is a 4-digit year followed by these 2-digit values (in order): month, day, year, hour (24-hour), minute, second, hundredths of a second.

Some of these commands return a 17-digit value for this format. If using this value to query the GainSeeker database, remove the 17th digit.

 

Syntax

Example

Description/Remarks

New or changed in GainSeeker version

hsidate.day

day = hsidate.day

Returns the current day of the month as an integer.

 

hsidate.dbdatetime()

dt = hsidate.dbdatetime()

Returns the current date/time as a 17-digit long integer (DB format).

When using this value to query the GainSeeker database, remove the seventeenth digit.

 

hsidate.dbdatetime(year, month, day, hour, minute, second, millisecond)

dt = hsidate.dbdatetime(2014, 10, 4, 5, 20, 45, 0)

Returns the input date/time (parameters) as a 17-digit long integer (DB format).

When using this value to query the GainSeeker database, remove the seventeenth digit.

 

hsidate.dbdatetimestr()

print hsidate.dbdatetimestr()

Returns the current date/time as a DB-formatted 17-character string (DB format)

When using this value to query the GainSeeker database, remove the seventeenth character. When setting dataspc.datetime or datadms.datetime the seventeenth character is automatically ignored.

 

hsidate.dbdatetimestr(year, month, day, hour, minute, second, millisecond)

print hsidate.dbdatetimestr(2014, 10, 4, 5, 20, 45, 0)

Returns the input date/time (parameters) as a DB-formatted 17-character string (DB format).

When using this value to query the GainSeeker database, remove the seventeenth character. When setting dataspc.datetime or datadms.datetime the seventeenth character is automatically ignored.

 

hsidate.dispdate()

print hsidate.dispdate()

Returns the current date as a display string.

 

hsidate.dispdatetime()

print hsidate.dispdatetime()

Returns the current date/time as a display string.

 

hsidate.disptime()

print hsidate.disptime()

Returns the current time as a display string.

 

hsidate.format_to_db(datetimestring)

print hsidate.format_to_db('02-28-2015')

returns 20150228000000000

Returns the input date/time (display string) as a 17-digit long integer (DB format).

Returns -1 if there was an error parsing the date/time.

When using this value to query the GainSeeker database, remove the seventeenth digit.

 

hsidate.format_to_db(datetimestring, formatstr)

print hsidate.format_to_db('31-05-2019', 'dd-MM-yyyy')

returns 20190531000000000

Returns the input date/time (display string) as a 17-digit long integer (DB format).

Use the formatstr parameter to specify the order of month, day, and year in the date/time string. For date/time format string options, see https://msdn.microsoft.com/en-us/library/8kb3ddd4(v=vs.110).aspx

Returns -1 if there was an error parsing the date/time.

When using this value to query the GainSeeker database, remove the seventeenth digit.

 

hsidate.formatdbdate(input, includedate,includetime)

print hsidate.formatdbdate(20120210, True, False)

returns 2/10/2012

Returns the input date/time (DB format) as a display string.

The input value can be an integer or a string and can be up to 17 characters long.

Set the includedate and/or includetime parameters to True if they are contained in the input date/time, otherwise set them to False).

 

hsidate.hour

hr = hsidate.hour

Returns the current hour as an integer (24-hour).

 

hsidate.millisecond

msec = hsidate.millisecond

Returns the current millisecond as an integer.

 

hsidate.minute

min = hsidate.minute

Returns the current minute as an integer.

 

hsidate.month

mnth = hsidate.month

Returns the current month as an integer.

 

hsidate.second

sec = hsidate.second

Returns the current second as an integer.

 

hsidate.timedelta(input, years=0, months=0, days=0, hours=0, minutes=0, seconds=0, milliseconds=0)

print hsidate.timedelta(20190531, months=-1)

returns 20190430000000000

Uses the input date/time (DB format) and offset parameters to return a new offset date/time as a a 17-digit long integer (DB format).

The input value can be an integer or a string and can be up to 17 characters long.

Offset parameters can be a positive integer (add time), a negative integer (subtract time), or 0 (no change; parameter is optional).

9.5

hsidate.validate(datetimestring)

if hsidate.validate("3/22/2013 8:59"):

     print "Valid date"

Returns True if a date/time display string is valid, using standard cultural formatting. Otherwise it returns False.

 

hsidate.validate(datetimestring, format)

if hsidate.validate("3/22/2013", "m/dd/yyyy"):

     print "Valid date"

Returns True if a date/time display string is valid, using the specified format. Otherwise it returns False.

See https://msdn.microsoft.com/en-us/library/8kb3ddd4%28v=vs.110%29.aspx for more information on format strings.

 

hsidate.year

yr = hsidate.year

Returns the current year as an integer.