473,699 Members | 2,147 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

DateAdd Function

Mel
When I use the DateAdd function using "DateInterval.W eekday" 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(DateInt erval.Weekday, 10, "11/04/2008")
'dPlanFD = #11/14/2008# 'I want it to return #11/18/2008#

Nov 4 '08 #1
3 6270
"Mel" <ML********@gma il.comwrote in message
news:cc******** *************** ***********@f37 g2000pri.google groups.com...
When I use the DateAdd function using "DateInterval.W eekday" 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.We ekday
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(ByV al pdtmDate As DateTime, ByVal pintInterval As
Integer) As DateTime
Dim intDays As Integer = 1
Do Until intDays pintInterval
pdtmDate = pdtmDate.AddDay s(1)
If pdtmDate.DayOfW eek <DayOfWeek.Satu rday And pdtmDate.DayOfW eek
<DayOfWeek.Sund ay Then
intDays = intDays + 1
End If
Loop
Return pdtmDate
End Function

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

Also, do yourself a *HUGE* favour and forget about the Microsoft.Visua lBasic
"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...@markNOSPA Mrae.netwrote:
"Mel" <MLights...@gma il.comwrote in message

news:cc******** *************** ***********@f37 g2000pri.google groups.com...
When I use the DateAdd function using "DateInterval.W eekday" 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.We ekday
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(ByV al pdtmDate As DateTime, ByVal pintInterval As
Integer) As DateTime
* * Dim intDays As Integer = 1
* * Do Until intDays pintInterval
* * * * pdtmDate = pdtmDate.AddDay s(1)
* * * * If pdtmDate.DayOfW eek <DayOfWeek.Satu rday And pdtmDate.DayOfW eek
<DayOfWeek.Sund ay Then
* * * * * * intDays = intDays + 1
* * * * End If
* * Loop
* * Return pdtmDate
End Function

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

Also, do yourself a *HUGE* favour and forget about the Microsoft.Visua lBasic
"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********@gma il.comwrote in message
news:0a******** *************** ***********@n33 g2000pri.google groups.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.Visua lBasic 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
3723
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) response.write testdate & "<br>"
0
2809
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 function in postgre. Can you help me? The function in MSDE is the following: ALTER FUNCTION dbo.slisp ( @UCESTALOST_BROJ int, @UCESTALOST_JEDINICA nvarchar (50),
1
17327
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 dateadd(year,1,dateadd(month,-1,getdate())) AND dateadd(day,-1,(dateadd(month,1,dateadd(year,1,dateadd(month,-1,getdate()))))) *************** (first part of the date calculation comes out to be '2005-05-01' and
2
37611
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 which is logical correct? But I want it to return end of month (i.e. 20041231) Any help in this context will be highly appreciated
1
4982
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 blank. I've tried; > >DateDiff("y",-4,DateIn) and get errors > >Please any assistance would be greatly appreciated. >
3
3725
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() ' if the table is in the same database Set rsAdd = db.OpenRecordset("tblClientTreatment") With rsAdd .AddNew !ClientID = Me.ClientID
4
10163
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 function for the beginning of the date range, like this: Between DateAdd("m",-1,!!) And !!
1
18992
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 AM", no date Example direct from VB Language Reference: Public Overloads Function DateAdd(ByVal Interval As DateInterval,_ ByVal Number As Double, ByVal DateValue As DateTime) As DateTime End Function
0
4455
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 function in postgre. Can you help me? The function in MSDE is the following: ALTER FUNCTION dbo.slisp ( @UCESTALOST_BROJ int, @UCESTALOST_JEDINICA nvarchar (50),
2
4554
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 dateinterval.second, an error is thrown saying I have an overflow. I would be happy to know if I am doing something wrong or if I could do it differently to get the seconds to display properly. Const largeInteger As Long = &H1C5EA3B5F585F1F Const...
0
8705
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
1
8943
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7785
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6550
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5884
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4637
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3075
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2362
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2016
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.