473,406 Members | 2,217 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Construct Projected Date

365 100+
Hello to all,

what i would like to do is have a bit of VB code to set a variable to the next tax year but am having trouble constructing it..

Taxdate = 01/04/year+1

so if this year 2008 then i want the taxt year to return the first monday around 01/04/2009
taking into account that if today was after new year the next taxdate would be the same... any ideas???

thanks for the interest
May 14 '08 #1
22 2238
patjones
931 Expert 512MB
Hello to all,

what i would like to do is have a bit of VB code to set a variable to the next tax year but am having trouble constructing it..

Taxdate = 01/04/year+1

so if this year 2008 then i want the taxt year to return the first monday around 01/04/2009
taking into account that if today was after new year the next taxdate would be the same... any ideas???

thanks for the interest
Look in the Access help pages for the DateAdd function. It has three arguments: the time interval you are working with (e.g. days, months, etc.), how many of those intervals you want to add, and the date you want to add to.

For instance, to add 25 days to May 14th, 2008, you could write DateAdd("d", 25, "14-May-2008"). For you, the only twist is that the number of intervals would have to be calculated depending on what the current date is, which you could probably use DateDiff for...

Pat
May 14 '08 #2
Dan2kx
365 100+
Its unfortunately the twist that i cant wrap my head around...

i would have to work out the date before i could work out the difference to work out the date, doesnt make sense does it is it possible to do something like this


if month(date) between 04 and12 then x = 1 else x = 0
taxdate = day(01)+month(04)+year(x)
May 14 '08 #3
patjones
931 Expert 512MB
Its unfortunately the twist that i cant wrap my head around...

i would have to work out the date before i could work out the difference to work out the date, doesnt make sense does it is it possible to do something like this


if month(date) between 04 and12 then x = 1 else x = 0
taxdate = day(01)+month(04)+year(x)
OK, try this:

Expand|Select|Wrap|Line Numbers
  1.  Dim intCurrentMonth As Integer 
  2. Dim intCurrentYear As Integer
  3. Dim intNextYear As Integer
  4.  
  5. Dim intNumOfDaysToAdd As Integer
  6.  
  7. Dim dteTaxDate As Date
  8.  
  9. intCurrentMonth = DatePart("m", Now)
  10. intCurrentYear = DatePart("yyyy", Now)
  11.  
  12. intNextYear = intCurrentYear+1
  13.  
  14. If intCurrentMonth >=4 And intCurrentMonth <=12 Then
  15.  
  16.      intNumOfDaysToAdd = DateDiff("d", Now, "1-April-" & intNextYear)     
  17.  
  18. Else
  19.  
  20.      intNumOfDaysToAdd = DateDiff("d", Now, "1-April-" & intCurrentYear)
  21.  
  22. EndIf
  23.  
  24. dteTaxDate = DateAdd("d", intNumOfDaysToAdd, Now)
  25.  
This is actually quick and dirty, because I'm using the VB canned date functions, but it seems to work with the examples I tried out in my Immediate Window...

Pat
May 14 '08 #4
Dan2kx
365 100+
genius that seems to work thanks!!
May 14 '08 #5
patjones
931 Expert 512MB
genius that seems to work thanks!!
It's no problem. And one other thing...when I ran it in my Immediate Window, I found that it returned dteTaxDate with the time of day part also. You might want to take action to get rid of that, depending on what your need is.

Pat
May 14 '08 #6
Dan2kx
365 100+
substituting "now" for "date" solved that problem

thanks again
May 14 '08 #7
NeoPa
32,556 Expert Mod 16PB
Expand|Select|Wrap|Line Numbers
  1. =CDate("1 April " & Year(Date())+IIf(Month(Date())<4,0,1))
May 16 '08 #8
patjones
931 Expert 512MB
Expand|Select|Wrap|Line Numbers
  1. =CDate("1 April " & Year(Date())+IIf(Month(Date())<4,0,1))
Now I'm eating my words "quick and dirty"...
May 16 '08 #9
NeoPa
32,556 Expert Mod 16PB
Not so fast Pat.

My solution doesn't find the Monday, it just finds the 1st of the month.
May 16 '08 #10
patjones
931 Expert 512MB
Not so fast Pat.

My solution doesn't find the Monday, it just finds the 1st of the month.
And neither does mine! Yikes...

This would find the first Monday after the tax date:

Expand|Select|Wrap|Line Numbers
  1.  Dim dteTaxDate As Date 
  2.  
  3. dteTaxDate=CDate("1 April " & Year(Date())+IIf(Month(Date())<4,0,1))
  4.  
  5. while DatePart("w",dteTaxDate) <> vbMonday
  6.      dteTaxDate = DateAdd("d", 1, dteTaxDate)
  7. wend
  8.  
Pat
May 16 '08 #11
NeoPa
32,556 Expert Mod 16PB
You can use the Weekday() function arithmetically to go straight to the correct date value :
Expand|Select|Wrap|Line Numbers
  1. Public Function TaxDate() As Date
  2.   TaxDate = CDate("1 April " & Year(Date()) + IIf(Month(Date()) < 4, 0, 1))
  3.   TaxDate = TaxDate + 7 - Weekday(TaxDate, vbTuesday)
  4. End Function
PS. The reason this is difficult (more complicated) in SQL is that the 1st April calculation would need to appear twice.
May 16 '08 #12
patjones
931 Expert 512MB
And neither does mine! Yikes...

This would find the first Monday after the tax date:

Expand|Select|Wrap|Line Numbers
  1.  Dim dteTaxDate As Date 
  2.  
  3. dteTaxDate=CDate("1 April " & Year(Date())+IIf(Month(Date())<4,0,1))
  4.  
  5. while DatePart("w",dteTaxDate) <> vbMonday
  6.      dteTaxDate = DateAdd("d", 1, dteTaxDate)
  7. wend
  8.  
Pat
I tried this out with several dates and it seems to work nicely, finding the nearest Monday to April 1st...

Expand|Select|Wrap|Line Numbers
  1.  Dim dteTaxDate As Date 
  2. Dim a As Integer
  3.  
  4. dteTaxDate = CDate("1 April " & Year(#12/6/2007#) + IIf(Month(#12/6/2007#) < 4, 0, 1))
  5.  
  6. a = DatePart("w", dteTaxDate, vbMonday) - 1
  7.  
  8. dteTaxDate = IIf(a <= 3, DateAdd("d", -a, dteTaxDate), DateAdd("d", 7 - a, dteTaxDate))
  9.  
Pat
May 16 '08 #13
FishVal
2,653 Expert 2GB
Hello, gentlemen.

It seems to me that the logic has a bug.
What will happen if current date is Sunday, 2 April?
May 16 '08 #14
NeoPa
32,556 Expert Mod 16PB
Then you get Monday 2nd April (2007).

I tested it (my code) for Sunday 2nd April 2006.

PS. Did you mean gentlemen? Or were you talking only of Pat's code?
May 16 '08 #15
FishVal
2,653 Expert 2GB
Then you get Monday 2nd April (2007).

I tested it (my code) for Sunday 2nd April 2006.
That is actually what I've meant. Don't you think Monday 3rd April 2006 would be the right answer?
May 16 '08 #16
NeoPa
32,556 Expert Mod 16PB
That makes a certain sense Fish, but from post #3, I would say no.
May 16 '08 #17
FishVal
2,653 Expert 2GB
That makes a certain sense Fish, but from post #3, I would say no.
Oh. Post #3 is not about "monday issue" at all. ;)
And, come on guys, don't you like this more challenging riddle?
May 17 '08 #18
NeoPa
32,556 Expert Mod 16PB
Oh. Post #3 is not about "monday issue" at all. ;)
Not sure I'd agree about post #3 there Fish. It's the OP's request spelled out is all. It's all one request.
And, come on guys, don't you like this more challenging riddle?
However, there may well have been confusion and, as a general rule, it's more fun dealing with the more complex formulae so we can look at it (the more challenging riddle) anyway.

I frankly can't see a way to subsume this new version into the existing logic, nor even produce new logic that incorporates this as a part of the whole. The best I can do at this time is to add a separate test at the front, which works fine, but isn't really very interesting I'm afraid.

If I can come up with a more unified (interesting) solution I will.
May 19 '08 #19
patjones
931 Expert 512MB
Hello, gentlemen.

It seems to me that the logic has a bug.
What will happen if current date is Sunday, 2 April?
I tested my code (well, really it's partly NeoPa's code also) in Post 13 with 4/2/2006 as the current date and it gives me 4/2/2007, which seems correct. Looking at Post 1, he wanted the closest Monday around April 1st, which 4/2/2007 satisfies...

The code that NeoPa wrote out with the IIf statement:

Expand|Select|Wrap|Line Numbers
  1. dteTaxDate = CDate("1 April " & Year(#4/2/2006#) + IIf(Month(#4/2/2006#) < 4, 0, 1))
  2.  
will advance the year by 1 so long as the current date falls on or after 4/1.

Pat
May 19 '08 #20
NeoPa
32,556 Expert Mod 16PB
Pat, the point is that the succeeding 1st Monday of April would actually be Monday 3rd April 2006.

...If you assume that "any date before April" actually means "any date before the first Monday in April".
May 19 '08 #21
patjones
931 Expert 512MB
Pat, the point is that the succeeding 1st Monday of April would actually be Monday 3rd April 2006.

...If you assume that "any date before April" actually means "any date before the first Monday in April".
Yes, I understand that, but my impression from Dan2kx's posts is that it should advance to the next year, even with a date like 4/2/2006. But we'd need him to clarify that, and he probably stopped reading like 15 posts ago! :-)

Pat
May 20 '08 #22
NeoPa
32,556 Expert Mod 16PB
Absolutely right Pat ;)
May 20 '08 #23

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Colleyville Alan | last post by:
I have some data in a table structured like this: Date Cust_ID CUSIP Amount 01/31/2005 060208 02507M303 27,061.84...
12
by: Laser Lu | last post by:
Hello, everybody, do you know how to use this Grouping Construct? (?> ) I've found its reference on MSDN, but still can not understand it totally. The following is its description: ...
6
by: c676228 | last post by:
Hi everyone, I searched on the internet and didn't get exactly what I want. Do you have any? -- Betty
27
by: pamela fluente | last post by:
Hello, for the following code, VS suggests that construct (width= height= ) is out of date and a newer one is recommended: <table><tr><td width="92" height="38" valign="middle">AnyThing</td></...
5
by: tvmadarsh | last post by:
Hai Pls help me to write a query I am having a table with name stock
0
by: Teebob | last post by:
How would I go about designing an application that you can enter the current year's sales by region (North,South,East and West) and the projected increase(%) in sales for each region? Application...
7
by: rz2026 | last post by:
Given a following table with two columns date value ------------------------ 01/01/2007 0 01/02/2007 1 01/05/2007 1 ...
1
by: dreamer1963 | last post by:
Write a line of code to declare and construct a Date object named curDate.
10
by: Atropo | last post by:
Hi all, Having several strings how do I construct variable to pass to system(): Lets say the date command string str = "14/10/08 19:06:09"; strDD = str.substr(0,2); strMM =...
2
by: Atropo | last post by:
sorry if this comes out more than once. i've posted this three times but never shows. Hi all, Having several strings how do I construct variable to pass to system(): Lets say the date...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.