April 27, 2024, 01:55:57 PM

News:

IonicWind Snippit Manager 2.xx Released!  Install it on a memory stick and take it with you!  With or without IWBasic!


Date Routine

Started by Brian, November 21, 2023, 04:59:22 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Brian

Help! This code works, and adds one day onto the current day, whatever it is

What I want it to do is put the result of this line: PRINT USING("##/##/####",st.wDay,st.wMonth,st.wYear)
into a STRING variable, like 'tomorrow' and include the leading zeros if a day is like '1' or a month is like '5', for example

Any ideas? Compile as a Console...

Brian

Brian

Had another think about it!

Brian

Egil

Brian,

I did something similar several years ago and converted it into CB.
Here is the CB code. and don't think you should have any problems to convert it to IWB and formatting the output in whatever way you like.
Thing are much more relaxed in CB when you want to format output, but don't think you should have any problems to convert it to IWB and formatting the output in whatever way you like.

Good Luck!
Egil
Support Amateur Radio  -  Have a ham  for dinner!

billhsln

Not sure who wrote this, but it will do date math.  I am just using it to calculate tomorrow.

$INCLUDE "windowssdk.inc"
AUTODEFINE "off"

DEF wdate:STRING

wdate=DATE$("yyyy-MM-dd")
wdate=datemath(wdate,1)

END

SUB DateMath(id:STRING,diff:INT),STRING
'======================================
DEF yyyy,mm,dd:INT
TYPE DateType
UINT LowDW
UINT HighDW
ENDTYPE

UNION uDT
UINT64 qVar
DateType dtVar
ENDUNION

SYSTEMTIME st
FILETIME ft
uDT u
INT rtn
'First get the system time so that all the other structure members are filled
GetSystemTime(st)
'Set up the SYSTEMTIME structure with the original date like so:
st.wYear=VAL(MID$(id,1,4))
st.wMonth=VAL(MID$(id,6,2))
st.wDay=VAL(MID$(id,9,2))
'Convert the system time to filetime
rtn=SystemTimeToFileTime(st,ft)
'Move the FILETIME info into a UINT64 variable
'and add days using the Quad variable (this is how M$ recommends doing it)
u.dtVar.LowDW=ft.dwLowDateTime
u.dtVar.HighDW=ft.dwHighDateTime
'Add days using the Quad variable - 1 day in nano seconds 24 * 60 * 60 * 10000000
u.qVar+=((24*60*60*10000000)*diff) ' <---- diff days
ft.dwLowDateTime=u.dtVar.LowDW
ft.dwHighDateTime=u.dtVar.HighDW
'Convert the file time to system time
rtn=FileTimeToSystemTime(ft,st)
'Now your new date will be in the SYSTEMTIME structure members
yyyy=st.wYear
mm=st.wMonth
dd=st.wDay
RETURN USING("0####&0##&0##",yyyy,"-",mm,"-",dd)
ENDSUB

Bill
When all else fails, get a bigger hammer.

Brian

Thanks, Chaps,

Nice to know somebody is alive and kicking on this forum!

Egil: Couldn't convert your code to IWB - my brain wasn't in gear
Bill: Your code was very similar to my solution that I posted

Thanks again,

Brian

Egil

Quote from: Brian on November 22, 2023, 08:09:25 AMgil: Couldn't convert your code to IWB - my brain wasn't in gear

And IWB does not work for me at the moment.
This kind of output formatting is one of the very few major differences between IWB and CB.
I may have an EB version of the same code, but then it is on a backup disk back home.
But think Bill's code is just right for you.


Good Luck to both of you.
Egil
Support Amateur Radio  -  Have a ham  for dinner!

Brian

Bill's code is the business - works great for me. I will post my program in a few days when I think I have done with it. Probably not useful to anyone else, but there are some good features in it

Brian