DATE$

Compatible with:
DOS Maximite CMM MM150 MM170 MM+ MMX Picromite ArmiteL4 Armite F4 ArmiteH7 Picomite CMM2

Syntax:
DATE$ = DD-MM-YY or DD/MM/YY
string$ = DATE$

Description:

DATE$ = DD-MM-YY or DATE$ = DD/MM/YY
Set the date of the internal clock/calendar. DD, MM and YY are numbers, for example: DATE$ = "28-7-2024" 
The year can be abbreviated to two digits (ie, 24). 

The ArmiteH7 and CMM2 use an internal RTC
The date is set to "01-01-2000" on first power up but the date will be remembered and kept updated as long as the battery is installed and can maintain a voltage of over 2.5V. 
Battery life should be 3 to 4 years even if the CMM2 is left powered off. 
Note that the time (set using the TIME$= command) will be lost when the power is cycled if a correct date is not set.

Other devices use an optional RTC module and use it to set the date and time on startup. AFter that, they use the main processor to maintain time.

See the RTC command for setting the external RTC module.

string$ = DATE$
Returns the current date based on MMBasic’s internal clock as a string in the form "DD-MM-YYYY". For example, "28-07-2012". 
The internal clock/calendar will keep track of the time and date including leap years. 
To set the date use the command DATE$ =.

Internally, the date assumes EU/UK/AU format day-month-year

To convert between this and the US month-day-year format, use a function such as USdate$()
When displaying dates, it can be an advantage to use names rather then numbers for the month to eliminate confusion.

 today$ = DATE$
 UStoday$ = USdate$(today$)
 EUtoday$ = USdate$(UStoday$)
 
 sortToday$ = sortDate$(today$)
 
 PRINT "Default format    ";today$
 PRINT "US date format    ";UStoday$
 PRINT "fn is reciprocal  ";EUtoday$
 PRINT
 PRINT "When you want to sort by date:"
 PRINT sortDate$(today$)
 PRINT sortDate$("27/09/21")
 PRINT sortDate$(DATE$+" "+TIME$)
 PRINT
 PRINT safeDate$(today$)
 
FUNCTION USdate$(dt$)
 USdate$ = MID$(dt$,4,2)+"-"+LEFT$(dt$,2)+"-"+MID$(dt$,7)
END FUNCTION
 
FUNCTION sortDate$(dt$)
 IF LEN(dt$) < 9 THEN ' assume we have 2 digit year
   sortDate$ = "20"+MID$(dt$,7,2)+"-"+MID$(dt$,4,2)+"-"+LEFT$(dt$,2)
 ELSE ' 4 digit year with optional time appended
   sortDate$ = MID$(dt$,7,4)+"-"+MID$(dt$,4,2)+"-"+LEFT$(dt$,2)+MID$(dt$,11)
 ENDIF
END FUNCTION
 
FUNCTION safeDate$(dt$)
 safeDate$ = LEFT$(dt$,2)+" "+MID$("  JanFebMarAprMayJunJulAugSepOctNovDec",VAL(MID$(dt$,4,2))*3,3)+" "+MID$(dt$,7)
END FUNCTION
 
Output:

Default format    15-09-2020
US date format    09-15-2020
fn is reciprocal  15-09-2020

When you want to sort by date:
2020-09-15
2021-09-27
2020-09-15 12:30:59

15 Sep 2020

Full error checking for dates entered by end users can get complex.

Last edited: 29 September, 2020