Menu
JAQForum Ver 19.10.27

Forum Index : Microcontroller and PC projects : Maximite Question II

Posted: 05:42am
09 Feb 2026
Copy link to clipboard
OA47
Guru


I have been struggling writing a sub that will enable a predicted TIME$ and DATE$ when a particular number of seconds are added. I tried using TIMER but the conversion back to DATE$ and TIME$ has become enormous. I have also started with a TIME$ and DATE$ and adding to the STRING values but having to modify for incrementing MINUTES, HOURS, DAYS, YEARS and LEAP YEARS is straining the grey matter to a large extent.

Has this been done by anyone or are there shortcuts that I am missing. I am stuck using MMBaisic 4.04 on a DTX-2 embedded module and unfortunately AI can't get enough data or information to help the situation.

OA47
 
Posted: 06:43am
09 Feb 2026
Copy link to clipboard
TassyJim
Guru


These are from 2014
Lucky they don't use line numbers.

Usage:
convert date,time to Unix
add the number of seconds.
convert back to date/time

 'date conversion routines
 currentdate$= DATE$
 currenttime$=TIME$
mainloop:
 DAY= VAL(MID$(currentdate$,1,2))
 month= VAL(MID$(currentdate$,4,2))
 year= VAL(MID$(currentdate$,7,4))
 hh=VAL(MID$(currenttime$,1,2))
 mm=VAL(MID$(currenttime$,4,2))
 ss=VAL(MID$(currenttime$,7,2))
 
 'weekday starts at 0 for Sunday to match the RTC chip
 d=DAY:m=month:y=year
 GOSUB toJD
 weekday= ABS((jd%+1) MOD 7) 'weekday starts at 0 for Sunday to match the RTC chip
 dayz$=MID$("SunMonTueWedThuFriSatSun",weekday*3+1,3)
 GOSUB toDOY
 PRINT currentdate$;"  ";currenttime$
 PRINT "Day of year: ";dayofyear
 PRINT "Julian Day : ";jd%
 PRINT "Day of Week: ";weekday;" ";dayz$
 d=DAY:m=month:y=year
 GOSUB tojdtime 'tounix
 PRINT "JD time  : ";jdd
 
 GOSUB fromjdtime 'fromunix
 PRINT udate$;"  ";utime$
 
 INPUT "New Date (DD/MM/YYYY) or X to quit: ",newdate$
 IF UCASE$(newdate$)="X" THEN END
 IF newdate$<>"" THEN currentdate$=newdate$
 INPUT "New Time (HH:MM:SS) : ",newtime$
 IF newtime$<>"" THEN currenttime$=newtime$
 IF (newtime$<>"") OR (newdate$<>"") THEN GOTO mainloop
 
testunix:
 INPUT "Unix time: ",un$
 IF un$="" THEN GOTO mainloop
 IF UCASE$(un$)="X" THEN END
 unix=VAL(un$)
 GOSUB fromunix
 PRINT "Unix time ";STR$(unix,12);" equals ";udate$;"  ";utime$
 GOTO testunix
 
tounix:
 d=DAY:m=month:y=year
 GOSUB toJD
 unixd=jd%-2440588
 hh=VAL(MID$(currenttime$,1,2))
 mm=VAL(MID$(currenttime$,4,2))
 ss=VAL(MID$(currenttime$,7,2))
 unixf=hh*60*60+mm*60+ss
 unix=unixd*86400+unixf
 RETURN
 
fromunix:
 unixd=INT(unix/86400)
 unixf=unix MOD 86400
 IF unixd<0 THEN
   unixf=86400+unixf
 ENDIF
 hh= INT(unixf/3600)
 mm= INT((unixf MOD 3600)/60)
 ss=(unixf MOD 3600) MOD 60
 jd%=unixd+2440588
 GOSUB fromJD
 udate$=STR$(d,2)+"/"+STR$(m,2)+"/"+STR$(y,4)
 utime$=STR$(hh,2)+":"+STR$(mm,2)+":"+STR$(ss,2)
 RETURN
 
toDOY:
 GOSUB toJD
 day1=jd%
 d=31:m=12:y=year-1
 GOSUB toJD
 dayofyear= day1-jd%
 jd%=day1
 RETURN
 
toJD:
 ' valid for Gregorian dates after Oct 15, 1582
 ff=FIX((m-14)/12)
 jd% = FIX((1461*(y+4800+ff))/4)+FIX((367*(m-2-12*ff))/12)-FIX((3*(FIX(y+4900+ff)/100))/4)+d-32075
 RETURN
 
fromJD:
 l = jd%+68569    ' valid for Gregorian dates after Oct 15, 1582
 n = FIX((4*l)/146097)
 l = l-FIX((146097*n+3)/4)
 i = FIX((4000*(l+1))/1461001)
 l = l-FIX((1461*i)/4)+31
 j = FIX((80*l)/2447)
 d = l-FIX((2447*j)/80)
 l = FIX(j/11)
 m = j+2-(12*l)
 y = 100*(n-49)+i+l
 RETURN
 
jdtounix:
 unix=jd%-2440588
 RETURN
 
tojdtime:
 d=DAY:m=month:y=year
 GOSUB toJD
 hh=VAL(MID$(currenttime$,1,2))
 mm=VAL(MID$(currenttime$,4,2))
 ss=VAL(MID$(currenttime$,7,2))
 jdt=(hh*60*60+mm*60+ss)/86400
 jdd=jd%+jdt
 RETURN
 
fromjdtime:
 jd%=INT(jdd)
 jdt=jdd-jd%
 GOSUB fromJD
 jdtime=jdt*86400
 hh= INT(jdtime/3600)
 mm= INT((jdtime MOD 3600)/60)
 ss=(jdtime MOD 3600) MOD 60
 udate$=STR$(d,2)+"/"+STR$(m,2)+"/"+STR$(y,4)
 utime$=STR$(hh,2)+":"+STR$(mm,2)+":"+STR$(ss,2)
 RETURN


Jim
 
Posted: 07:07am
09 Feb 2026
Copy link to clipboard
Volhout
Guru

Hi Jim,

Good that you found something. I can't go back before 4.5C on CMM1. Is 4.04 a mono maximite ?

P.S. Off-Topic: did you already find a "final" solution for the MMCC 5.40 linux problem. You found a "quick fix" but needed more testing ?

Volhout
 
Posted: 07:12am
09 Feb 2026
Copy link to clipboard
TassyJim
Guru


  Volhout said  Hi Jim,

P.S. Off-Topic: did you already find a "final" solution for the MMCC 5.40 linux problem. You found a "quick fix" but needed more testing ?

Volhout

I am never 100% confident.
Time will tell how well I have done.

Jim
 
Posted: 01:12pm
09 Feb 2026
Copy link to clipboard
Pluto
Guru

Could the EPOCH functions be useful?
 
Posted: 02:39pm
09 Feb 2026
Copy link to clipboard
Volhout
Guru

Hi Pluto,

According MMBasic 4.5C language manual (CMM1), the EPOCH function is not implemented in this version of basic. I am not sure about 4.04, but my estimate is it is not available.

Volhout
 
Posted: 02:49pm
09 Feb 2026
Copy link to clipboard
Volhout
Guru

@OA47,

There is a version 4.5 MMBasic for the DTX2. Please find attached.
They fixed some bugs with DATE$ and TIME$ according the release notes.

mmbasic.zip

Volhout

P.S. They added some nice commands to MMBasic. Especially the simple multithread  capability. But also "HELP"...
Edited 2026-02-10 01:02 by Volhout
 


To reply to this topic, you need to log in.

The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2026