Page History: Now() Function (VB work-a-like)
Compare Page Revisions
Page Revision: 2017/11/20 16:45
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.
The output string from Now() can be passed directly to the
UnixTime function.
In a touching
homage to VB, this function must be followed by brackets as a dummy argument - not doing so will confuse MMBasic over variables Vs functions
Syntax: Now()
Examples:x$=Now()
Print Now();" system startup"
If Daylight(Now()) Then ...
Print#3,Unixtime(Now())+" system halted"
Code:
Function Now(dummy$) as string ' d$ is a dummy string to make the function syntax work nicely
Now=Date$+" "+Time$
End Function