Date and Time

In this chapter we are going to learn about the date and time functions.

Clock() Function

Syntax:

Clock() ---> The number of clock ticks from program start

Example:

See "Calculate performance" + nl
t1 = clock()
for x = 1 to 1000000 next
see clock() - t1

ClocksPerSecond() Function

Return how many clocks in one second

Syntax:

clockspersecond() ---> Number of clocks in one second

Example:

# Wait 1 second
t = clock()
while clock() - t <= clockspersecond() end

Time() Function

We can get the system time using the Time() function.

Example:

See "Time : " + time()

Date() Function

We can get the date using the Date() function.

Syntax:

Date() ---> String represent the date "dd/mm/yyyy"

Example:

See "Date : " + date()  # Date : 24/05/2015

TimeList() Function

We can print the date and the time information using the TimeList() function.

Syntax:

TimeList() ---> List contains the time and date information.

The next table presents the list items

index value
1 abbreviated weekday name
2 full weekday name
3 abbreviated month name
4 full month name
5 Date & Time
6 Day of the month
7 Hour (24)
8 Hour (12)
9 Day of the year
10 Month of the year
11 Minutes after hour
12 AM or PM
13 Seconds after the hour
14 Week of the year (sun-sat)
15 day of the week
16 date
17 time
18 year of the century
19 year
20 time zone
21 percent sign

Example:

/* Output:
** Sun                  abbreviated weekday name
** Sunday               full weekday name
** May                  abbreviated month name
** May                  full month name
** 05/24/15 09:58:38    Date & Time
** 24                   Day of the month
** 09                   Hour (24)
** 09                   Hour (12)
** 144                  Day of the year
** 05                   Month of the year
** 58                   Minutes after hour
** AM                   AM or PM
** 38                   Seconds after the hour
** 21                   Week of the year (sun-sat)
** 0                    day of the week
** 05/24/15             date
** 09:58:38             time
** 15                   year of the century
** 2015                 year
** Arab Standard Time   time zone
** %                    percent sign
*/

See TimeList()

Example:

See "Day Name : " + TimeList()[2]       # Sunday

Example:

See "Month Name : " + TimeList()[4]     # May

AddDays() Function

Syntax:

AddDays(cDate,nDays) ---> Date from cDate and after nDays

Example:

cDate = date()
see cDate + nl                  # 24/05/2015
cDate = adddays(cDate,10)
see cDate + nl                  # 03/06/2015

DiffDays() Function

Syntax:

DiffDays(cDate1,cDate2) ---> number of days (Date1 - Date2)

Example:

cDate1 = date()
see cDate1 + nl                                         # 24/05/2015
cDate2 = adddays(cDate1,10)
see cDate2 + nl                                         # 03/06/2015
see "DiffDays = " + diffdays(cDate1,cDate2) + nl        # -10
see "DiffDays = " + diffdays(cDate2,cDate1) + nl        # 10