Modern languages have extended data types beyond simple strings or numeric. VB has a time datatype which allows addition, subtraction, weekday, month and formatting all with dates as if they were numbers in the conventional sense.
VB's Now() function returns the current system time in a date-type format but if you assign it to a string or simply "print" it, it is converted into DD/MM/YYYY HH:MM:SS which is arguably the most useful format to default to.
Although MMBasic can't hope to support the different datatypes of modern languages, the Now() function is really useful instead of having to construct it each time. This function does that - OK, it isn't rocket science to concatenate the DATE$ and TIME$ but it reduces program size and, I think, makes program flow easier to read.
Now() supports an optional date-format parameter. The default is zero which results in the date following the system format of DD-MM-YYYY. If opt is non-zero, the data part follows the
ISO8601format of YYYY-MM-DD. The output string from Now() can be passed directly to the
UnixTime function - be sure to maintain the date format option across the two (applies to HumanTime also).
Syntax: Now([opt])
Examples:x$=Now() ' same as
x$=Now(0)
Print Now(1);" system startup"
If Daylight(Now()) Then ...
Print#3,Unixtime(Now())+" system halted"
Code:
Function Now(opt as Integer) as string
Local a$
Do ' ensure the date/time doesn't change while we are processing
a$=Date$+" "+Time$
Now=Date$+" "+Time$
Loop While a$<>Now
If opt<>0 then
Now=Mid$(a$,7,4)+Mid$(a$,3,4)+Left$(a$,2)+Mid$(a$,11)
EndIf
End Function
See Also:
DateAdd()DateDiff()DatePart()