# Thread: Having trouble with dates

1. ## Having trouble with dates

Basically, i'm trying to add days to the system date (Sysdate) but it gives me invalid numbers such as -16 or 44, when obviously, it should be a valid calender date. I'm not very good at explaining, as you might have gathered, so i'll post the code i've got so far. Hopefully, someone will be able to help.

Cheers.
Dim SysDate, SysDays, SysMths, SysYrs, USdate

'Define Days here
SysDate = Date
SysDays = Day(SysDate)
SysDays2 = SysDays + 7
SysDays3 = SysDays + 10
SysDays4 = SysDays + 14
SysDays5 = Day(SysDate) + 40
SysDays6 = SysDays - 20

'Define Months here
SysMths = Month(SysDate)
SysMths2 = SysMths + 1

'Define Years here
SysYrs = Year(SysDate)
SysYrs2 = SysYrs - 30
SysYrs3 = SysYrs - 3
SysYrs4 = SysYrs - 1
SysYrs5 = SysYrs +1

'need to add a zero in front of days/mths when &lt;10 otherwise will become ‘6’ instead of 06
If SysDays &lt;10 Then
SysDays = "0" &amp; SysDays
End If
If SysDays2 &lt;10 Then
SysDays2 = "0" &amp; SysDays2
End If
If SysDays3 &lt;10 Then
SysDays3 = "0" &amp; SysDays3
End If
If SysDays4 &lt;10 Then
SysDays4 = "0" &amp; SysDays4
End If
If SysDays5 &lt;10 Then
SysDays5 = "0" &amp; SysDays5
End If
If SysDays6 &lt;10 Then
SysDays6 = "0" &amp; SysDays6
End If
If SysDays7 &lt;10 Then
SysDays7 = "0" &amp; SysDays7
End If

If SysMths &lt;10 Then
SysMths = "0" &amp; SysMths
End If
If SysMths2 &lt;10 Then
SysMths2 = "0" &amp; SysMths2
End If

'Define USdates here
'put dates into US format USdate = system date
USdate = SysMths &amp; "/" &amp; SysDays &amp; "/" &amp; SysYrs 'Current date in USformat
USdate2 = SysMths &amp; "/" &amp; SysDays &amp; "/" &amp; SysYrs2 'Todays date - 30yrs
USdate3 = SysMths &amp; "/" &amp; SysDays &amp; "/" &amp; SysYrs3 'Todays date - 3yrs
USdate4 = SysMths &amp; "/" &amp; SysDays &amp; "/" &amp; SysYrs4 'Todays date - 1yr
USdate5 = SysMths &amp; "/" &amp; SysDays &amp; "/" &amp; SysYrs5 'Todays date + 1yr
USdate6 = SysMths2 &amp; "/" &amp; SysDays &amp; "/" &amp; SysYrs 'Todays date + 1Mth
USdate7 = SysMths &amp; "/" &amp; SysDays2 &amp; "/" &amp; SysYrs 'Todays date + 7days
USdate8 = SysMths &amp; "/" &amp; SysDays3 &amp; "/" &amp; SysYrs 'Todays date + 10days
USdate9 = SysMths &amp; "/" &amp; SysDays4 &amp; "/" &amp; SysYrs 'Todays date + 14days
USdate10 = SysMths &amp; "/" &amp; SysDays5 &amp; "/" &amp; SysYrs 'Todays date + 20days
USdate11 = SysMths &amp; "/" &amp; SysDays6 &amp; "/" &amp; SysYrs 'Todays date - 20days

3. ## Re: Having trouble with dates

so to add 7 days from now you would do:

msgbox myDate

4. ## Re: Having trouble with dates

thanks guys, i'll try them.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•

vBulletin Optimisation provided by vB Optimise v2.6.0 Beta 4 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.