Help getting the date of the Tuesday, 3 weeks away

I haven’t worked much with dates in Xojo; nothing beyond getting the current date and formatting it the way I want.
For this application I’m building I’m displaying the date as an SQLDate formatted as (today would be): 2000904.
Year 2020 = 20
Month 9 = 09
Day 4 = 04
This becomes the default text of a textbox and is used as the first part of a naming convention for a column in one of our tables of the DB.
I was just told I need to make that date be 3 weeks in the future, on Tuesday.

So using today as the example from above (200904)
The date should actually display 200922, as that is 3 weeks away on Tuesday.

I’m having a rather difficult time figuring this out without coding a bunch of if statements and selects. Which I’m not doing because it seems like a waste of time. There has to be a cleaner more efficient way.

Here is my current code so you can at least see my thought process.

dim d as new date
dim todaysDate as string
todaysDate = d.SQLDate
dim d2 as new date
dim futureDate as string
futureDate = d2.SQLDate

//todaysDate
dim day As Integer = d.DayOfWeek
dim week as integer = d.WeekOfYear

dim dd as String
dim mm as String
dim yy as string

yy = todaysDate.Left(2)
mm = todaysDate.Mid(6, 2)
dd = todaysDate.Mid(9, 2)
dim ddd as integer = val(dd)
ddd = ddd + 21
todaysDate = (yy + mm + dd)


//futureDate
dim newDay as integer = 2
dim newWeek as Integer = week + 3

dim dd2 as string
dim mm2 as string
dim yy2 as string

yy2 = futureDate.left(2)
//mm2 = 

futureDate = (yy + mm + newDay.ToText)

MsgBox("Todays date: " + todaysDate)
MsgBox("1st Tuesday 3 weeks from today: " + futureDate)

Any ideas to point me in the right direction?

I HAVE to ask why you’d name a column prefixed with a date like that but …
thats not really the key here

Dim d as new date

// add 3 weeks worth of seconds
d.totalseconds = d.totalseconds + ( 24 * 60 * 60) * 21

Also, this might help:

sFormattedDate = todaysDate.SQLDate.ReplaceAll("-", "")
1 Like

It’s not a column. It’s a textbox for them to name an entry in the table.

Ah I did say column. My mistake.
Seconds… why didn’t I even look at that.
Thanks @Norman_Palardy

Obviously I misunderstood that from the description of the problem

Either way its all good :slight_smile:
You can add totalseconds or 21 days using the older Date class
in the newer DateTime youd use a dateinterval but the underlying principle is the same

…then work backwards (or forwards) to Tuesday, as required.

Yeah we’re still using v2019 so I don’t have access to dateinterval. But this is definitely what I’m looking for. Thanks again.

Offlist someone else asked for the DateTime and DateInterval version

Dim base As datetime = datetime.now

// add 21 days
Dim inter As New DateInterval(0,0,21)

Dim result As datetime = base + inter

1 Like

This should also adjust to the ‘Tuesday’ (day 3) of that week:

d.totalseconds = d.totalseconds + ( 24 * 60 * 60) * (21 - (3 - d.DayOfWeek))