Fandom

Livecode Wiki

Convert

2,161pages on
this wiki
Add New Page
Comments0 Share

Changes a date, a time, or a date and time to a specified format.

Syntax:

convert dateAndTime [from format [and format]] to format [and format]

Examples:

convert "11/22/90" to long english date
convert the internet date from internet date to system date
convert lastChangedTime to abbreviated time and long date
convert the date && the time to seconds

Use the convert command to change a date or time to a format that's more convenient for calculation or display.

The dateAndTime is a string or container with a date, a time, or a date and time separated by a space, tab, or return character.

The format is one of the following (examples are February 17, 2000 at 10:13:21 PM, in the Eastern time zone, using US date and time formats):

  • short date: 2/17/00
  • abbreviated date: Thu, Feb 17, 2000
  • long date: Thursday, February 17, 2000
  • short time: 10:13 PM
  • abbreviated time: 10:13 PM
  • long time: 10:13:21 PM
  • internet date: Thu, 17 Feb 2000 22:13:21 -0500
  • seconds: the number of seconds since the start of the eon
  • dateItems: 2000,2,17,22,13,21,5

If you specify both a date and time format, they can be in either order and must be separated by a space. The resulting date and time are in the order you provided, separated by a space. If you specify seconds or dateItems, you can request only one format.

If the dateAndTime is a container, the converted date and time is placed in the container, replacing the previous contents. If the dateAndTime is a string, the converted date and time is placed in the it variable.

The dateItems format is a comma-separated list of numbers:

  1. the year
  2. the month number
  3. the day of the month
  4. the hour in 24-hour time
  5. the minute
  6. the second
  7. the numeric day of the week where Sunday is day 1, Monday is day 2, and so forth

The convert command can handle dates in dateItems format where one or more of the items is out of the normal range. This means you can add arbitrary numbers to an item in the dateItems and let the convert command handle the calculations that span minute, hour, day, month, and year boundaries.

For example, suppose you start with 9:30 AM , convert that time to dateItems format, then add 45 minutes to item 5 (the minute) of the resulting value. This gives you 75 as the minute. When you convert the value to any other time format, the convert command automatically converts "75 minutes" to "1 hour and 15 minutes":

 convert "9:30 AM" to dateItems
 add 45 to item 5 of it
 convert it to time -- yields "10:15 AM"

You can optionally use the english or system keyword before the short, abbreviated, or long date or time. If the useSystemDate is true, or if you use the system keyword, the user's current system preferences are used to format the date or time. Otherwise, the standard US date and time formats are used.

The internet date, seconds, and dateItems formats are invariant and do not change according to the user's preferences.

The convert command assumes all dates / times are in local time except for 'the seconds', which is taken to be universal time.

If you convert a date without a time to a form that includes the time, the time will be given as midnight local time.

The range of dates that the convert command can handle is limited by the operating system's date routines. In particular, Windows systems are limited to dates after 1/1/1970.


See Also: dateFormat Function, time Function, milliseconds Function, date Function, sort container Command, twelveHourTime Property, centuryCutoff Property

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.