473,326 Members | 2,337 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,326 software developers and data experts.

DateAdd Function

Mel
When I use the DateAdd function using "DateInterval.Weekday" it does
not return the correct date, well at least how I thought the weekday
option should work. It is counting weekends and I only want it to
count the weekdays (Mon-Fri). How can I get it to work? (using
Asp.net 2.0, vb.net)

Example:
dPlanFD = DateAdd(DateInterval.Weekday, 10, "11/04/2008")
'dPlanFD = #11/14/2008# 'I want it to return #11/18/2008#

Nov 4 '08 #1
3 6250
"Mel" <ML********@gmail.comwrote in message
news:cc**********************************@f37g2000 pri.googlegroups.com...
When I use the DateAdd function using "DateInterval.Weekday" it does
not return the correct date, well at least how I thought the weekday
option should work.
A quick glance at the documentation will tell you what DateInterval.Weekday
actually means:
http://msdn.microsoft.com/en-us/libr...einterval.aspx
It is counting weekends and I only want it to count the weekdays
(Mon-Fri).
How can I get it to work? (using Asp.net 2.0, vb.net)
Write your own function, something like this:

Function WeekdayDiff(ByVal pdtmDate As DateTime, ByVal pintInterval As
Integer) As DateTime
Dim intDays As Integer = 1
Do Until intDays pintInterval
pdtmDate = pdtmDate.AddDays(1)
If pdtmDate.DayOfWeek <DayOfWeek.Saturday And pdtmDate.DayOfWeek
<DayOfWeek.Sunday Then
intDays = intDays + 1
End If
Loop
Return pdtmDate
End Function

And call it like this: Dim dtmEnd As DateTime = WeekdayDiff(DateTime.Now,
10)

Also, do yourself a *HUGE* favour and forget about the Microsoft.VisualBasic
"training wheels" namespace...
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Nov 4 '08 #2
Mel
On Nov 4, 11:49*am, "Mark Rae [MVP]" <m...@markNOSPAMrae.netwrote:
"Mel" <MLights...@gmail.comwrote in message

news:cc**********************************@f37g2000 pri.googlegroups.com...
When I use the DateAdd function using "DateInterval.Weekday" it does
not return the correct date, well at least how I thought the weekday
option should work.

A quick glance at the documentation will tell you what DateInterval.Weekday
actually means:http://msdn.microsoft.com/en-us/libr...lbasic.dateint...
It is counting weekends and I only want it to count the weekdays
(Mon-Fri).
How can I get it to work? (using Asp.net 2.0, vb.net)

Write your own function, something like this:

Function WeekdayDiff(ByVal pdtmDate As DateTime, ByVal pintInterval As
Integer) As DateTime
* * Dim intDays As Integer = 1
* * Do Until intDays pintInterval
* * * * pdtmDate = pdtmDate.AddDays(1)
* * * * If pdtmDate.DayOfWeek <DayOfWeek.Saturday And pdtmDate.DayOfWeek
<DayOfWeek.Sunday Then
* * * * * * intDays = intDays + 1
* * * * End If
* * Loop
* * Return pdtmDate
End Function

And call it like this: Dim dtmEnd As DateTime = WeekdayDiff(DateTime.Now,
10)

Also, do yourself a *HUGE* favour and forget about the Microsoft.VisualBasic
"training wheels" namespace...

--
Mark Rae
ASP.NET MVPhttp://www.markrae.net
That works. I adjusted it a little so it will subtract days too if
the interval is less than zero (I have some tasks that run from Finish
to Start). It works, very cool thank you. Too bad the DateAdd
function won't do it automatically but oh well.

:)
Nov 7 '08 #3
"Mel" <ML********@gmail.comwrote in message
news:0a**********************************@n33g2000 pri.googlegroups.com...
Too bad the DateAdd function won't do it
Rich as the .NET Framework is, it can't accommodate every single requirement
of every single developer in the whole world - there wouldn't be a hard disk
big enough to install it on...

Please do give serious consideration to doing without the
Microsoft.VisualBasic namespace, though, especially if you're serious about
..NET development:
http://www.codeproject.com/KB/vb/novbruntimeref.aspx
http://www.knowdotnet.com/articles/f...namespace.html

And if you absolutely must use VB.NET, make sure you always have Option
Strict on...
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Nov 7 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Gabe | last post by:
Please see: http://www.showorders.com/test3.asp The code generating the page is as follows: testdate = "1/29/2003 1:00:00 PM" while count <> 5 testdate = dateadd("n",15,testdate)...
0
by: Zlatko Matiæ | last post by:
I am currently migrating from MSDE to PostgreSQL and have to rewrite the function that is calculating next date of sampling... In MSDE there is a DateAdd function. I can't find the appropriate...
1
by: Raghu | last post by:
Hello... I am running into a problem while running a query..can some1 help.. this is the query : ************** SELECT * from Table S where S.dtDate1 BETWEEN...
2
by: Abdul N K | last post by:
I need help in T-SQL. I am using DATEADD function and I want to add 6 months to a date. But it does not return me the rusults, which I want e.g. SELECT DATEADD(m,'20040630') returns 20041230...
1
by: PMBragg | last post by:
ORINGINAL Post >Thank you in advance. I'm trying to pull all inventory items from December >of the previous year back to 4 years for my accountant. I know this can be >done, but I'm drawing a...
3
by: Annette Massie | last post by:
I am trying to insert a record into a table via code and one of the values to add I would like as a dateadd calculation on a value from a query. My code looks like this: Set db = CurrentDb() ...
4
by: ey.markov | last post by:
Greetings, I have an A2K application where for a report the user enters a month-end date, and the system must gather transactions for that month. No problem, I thought, I'll just use the DateAdd...
1
by: C.Davidson | last post by:
Does subject VB.net 2003 support DateAdd function? I have tried to implement the following without success. In my example I tried to simply add 30 months to 9/18/2003 and I get "New date: 12:00:00...
0
by: Zlatko Matiæ | last post by:
I am currently migrating from MSDE to PostgreSQL and have to rewrite the function that is calculating next date of sampling... In MSDE there is a DateAdd function. I can't find the appropriate...
2
by: Rich Raffenetti | last post by:
I have the following code. If I do the dateadd function with dateinterval.minute, it works fine and the date/time value is displayed with zero seconds. If I do the dateadd function with...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.