StringToTime() function - 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

Purpose

Returns a Time value given a string that represents a time. You can call this function from the MapBasic window in MapInfo Pro.

Syntax

StringToTime( "timeString", "timeFormat", "locale" )

timeString is a string that represents a time.

timeFormat is an optional string expression representing the time format to apply (overriding the system time format ).

locale is an optional string expression representing the locale of the time format applied.

Return Value

Time

Description

MapBasic interprets the time string according to the time-formatting options that are set up on the computer. However, either 12 or 24-hour time representations are accepted. The less significant components of a time may be omitted, so the hour must be specified, but the minutes, seconds, and milliseconds are optional.

You can also use the optional timeFormat and locale arguments to explicitly apply time formatting conventions.

Example

This examples uses a United States time format where colons separate hours (hh), minutes (mm), seconds (ss), and fractions (fff), (for details, see Time or FormatTime$() function).

dim strY as string
dim X as time
strY = "12:32:45"
X = StringtoTime(strY)
Print FormatTime$ (X,"hh:mm:ss.fff tt")

Short Time format in US (AM or PM):

Print StringToTime("06.04.2021 3:20:35 PM","dd.MM.yyyy h:mm:ss tt", "en-US")
//returns: 152035000

Long Time format in US (AM or PM):

Print StringToTime ("Monday, June 15, 2009 12:09:25 PM","dddd, MMMM d, yyyy h:mm:ss tt", "en-US")
//returns: 120925000

Long Time format in Denmark (24 Hour clock):

Print StringToTime ("Mandag, Juni 15, 2009 15:20:35","dddd, MMMM d, yyyy HH:mm:ss", "da-DK")
//returns: 152035000

Long Time format in Germany:

Print StringToTime ("Montag, 15. Juni 2009","dddd, dd. MMMM yyyy", "de-DE")
//returns: 20090615

Long Time format in Finnish (24 Hour clock):

Print StringToTime ("maanantai, kesäkuu 15, 2009 15:20:35","dddd, MMMM d, yyyy HH:mm:ss", "fi-FI")
//returns: 152035000

Short Time format in France (24 Hour clock):

Print StringToTime ("2009.06.15 15:20:35","yyyy.MM.dd HH:mm:ss", "fr-FR")
//returns: 152035000

See Also:

Date and Time Functions, NumberToDateTime() function, NumberToTime() function, Set Format statement, Str$() function, StringToTime() function