Date and Time Functions - MapBasic - 2023

MapInfo MapBasic Reference

Product type
Software
Portfolio
Locate
Product family
MapInfo
Product
MapInfo > MapBasic
Version
2023
Language
English
Product name
MapBasic
Title
MapInfo MapBasic Reference
First publish date
1985
Last updated
2023-09-12
Published on
2023-09-12T16:32:32.686312
Obtain the current date CurDate()
Extract parts of a date value: Day(), Month(), Weekday(), Year()
Obtains the current time as a formatted string: Time()
Creates a date from a number or a string: NumberToDate(), StringToDate()
Obtain the current Time or DateTime: CurTime(),CurDateTime()
Obtain the Date or Time from a DateTime value: GetDate(),GetTime()
Create a DateTime or Time value from a number: NumberToDateTime(),NumberToTime()
Create a DateTime value from two individual Date and Time values: MakeDateTime()
Create a DateTime or Time value from a string: StringToDateTime(),StringToTime()
Creates a string representation of a Date or Time value: FormatDate$(), FormatTime$()
Extract parts of a Time value: Hour(), Minute(), Second()
Sets and gets the rule for two-digit year input: Set Date Window(), DateWindow()

DateTime

A DateTime value represents a date. When you enter a number or a string in MapBasic, it automatically converts them to DateTime values when those values are assigned to a DateTime field in a table or a DateTime variable in MapBasic.

You can use a sequence of 17 digits to represents a date:

  • 4 for the year
  • 2 each for the month, day, hour, minutes, and seconds
  • 3 for milliseconds

A sequence of digits is a number if there are no quotes and a string when in quotes. If entering fewer than 17 digits, then a string and number are interpreted differently. A string has zeroes added to the right and a number has zeroes added to the left, so "20150909" would be evaluated as the string "20150909000000000" while 20150909 would be evaluated as the number 00000000020150909.

MapBasic interprets a date string according to the date-formatting options that are set up on your computer. The international standard date notation is:

YYYY-MM-DD

Where YYYY is the year, MM is the month between 01 (January) and 12 (December), and DD is the day of the month between 01 and 31. The separator character may vary, such as period (.), dash (-), or backslash (/).

Computers within the United States are configured to format dates as Month/Day/Year. The United States date notion is:

MM/DD/YYYY

To apply United States formatting conventions, use the Set Format statement. To avoid the issue of how your computer is set up, call the NumberToDate() function, which is not affected by your computer set up.

When entering data into a DateTime field in the MapInfo Pro Browser window or Info tool, the value processes as a string. Quotes are not necessary around the value and time separators, such as a backslash (/) and colon (:), are accepted. The exception is the Update Column dialog, which requires quotes around string values.

Functions that return a DateTime value are:

Date

A Date value is an integer representing the date in a YYYYMMDD format, where YYYY is the year, MM is the month between 01 (January) and 12 (December), and DD is the day of the month between 01 and 31.

Functions that return a DateTime value are CurDate() function, GetDate() function, and NumberToDate() function.

Time

A Time value is an nine-digit integer in the form hhmmssfff, where hh is hour, mm is minutes, ss is seconds, and fff is fractions. For example, 214237582 represents 9:42:37.582 P.M.

Functions that return a Time value are:

A function like FormatTime$() function lets you specify the time format to apply to the output. You should follow the same Microsoft standards as for setting the locale time format as outlined in the following list. The letters m, s, and t must be lowercase and the letter h must be lowercase (h) to denote the 12-hour clock or uppercase (H) to denote the 24-hour clock. In addition to this, you can also specify f, ff, or fff for tenths of a second, hundredths of a second, or milliseconds.

Hours Meaning
h Hours without leading zeros for single-digit hours (12-hour clock).
hh Hours with leading zeros for single-digit hours (12-hour clock).
H Hours without leading zeros for single-digit hours (24-hour clock).
HH Hours with leading zeros for single-digit hours (24-hour clock).
Minutes Meaning
m Minutes without leading zeros for single-digit minutes.
mm Minutes with leading zeros for single-digit minutes.
Seconds Meaning
s Seconds without leading zeros for single-digit seconds.
ss Seconds with leading zeros for single-digit seconds.
Time marker Meaning
t One-character time marker string.
Note: Do not to use this format for certain languages, for example, Japanese (Japan). With this format, the application always takes the first character from the time marker string, defined by LOCALE_S1159 (AM) and LOCALE_S2359 (PM). Because of this, the application can create incorrect formatting with the same string used for both AM and PM.
tt Multi-character time marker string.

Source: http://msdn2.microsoft.com/en-us/library/ms776320.aspx