473,387 Members | 3,801 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,387 software developers and data experts.

DateDiff function

3
Hi. I am a novice user. I am using the datediff function in a query. I am trying to calculate the number of week days between two dates. When I use "m" as the interval, the number of weeks is returned. When I use "d" or "y" as the interval, the number of days is returned. What kind of calculation can I add to the statement to only count the number of week days? Is this possible?

I was thinking I might have to run a query on a query and put in a formula that somehow subtracts 2 days from every 7. The next problem would be if there were only 6 days. Then I would only want it to subtract 1 day.

thanks in advance for your help.
Sep 27 '07 #1
7 5935
missinglinq
3,532 Expert 2GB
An interval of “m” should give you months, not weeks! The following site has 2 different functions for calculating week/work days, one that does just that and a more complicated one that allows for the exclusion of certain holidays.

Calculating Work/Week Days

Welcome to TheScripts!

Linq ;0)>
Sep 27 '07 #2
JenM
3
An interval of “m” should give you months, not weeks! The following site has 2 different functions for calculating week/work days, one that does just that and a more complicated one that allows for the exclusion of certain holidays.

Calculating Work/Week Days

Welcome to TheScripts!

Linq ;0)>
Thank you. Yes, I did mean "w" as the interval. Where/how do I enter the code in a query builder?
Sep 27 '07 #3
Denburt
1,356 Expert 1GB
The link he provided you with should do what you need. You would place the code into a module in VBA then in the query you can use something to define the field name and it would look something like this:

NumberOfWeekDays:WorkingDays(StartDate, EndDate)

This should give you the results you need let us know how it goes.
Sep 27 '07 #4
JenM
3
The link he provided you with should do what you need. You would place the code into a module in VBA then in the query you can use something to define the field name and it would look something like this:

NumberOfWeekDays:WorkingDays(StartDate, EndDate)

This should give you the results you need let us know how it goes.
Thank you for your help. I apologize for having trouble with something that must be simple. I'm not sure how to insert/run the module in the query. I created a module and used your suggestion for the field name in the query, but I received the following error "undefined function 'WorkingDays' in expression."
Oct 2 '07 #5
martin DH
114 100+
I'd like to piggyback on this post if I could.

I'm trying to display the DateDiff result in a textbox on a report; my starting date is a field [SubmittedDate] and my ending date is Now() - I want it to calc the number of weekdays between the submitted date and whenever the report is ran.
I used the module posted (WorkingDays), changed its starting and ending dates to reflect my fields, created a textbox on my report with a control source of the WorkingDays function. When I run the report I get parameter boxes asking for "WorkingDays", "SubmittedDate", and "Now()" and then "Error" in the textbox on the completed report.

Advice?
Oct 3 '07 #6
Denburt
1,356 Expert 1GB
Thank you for your help. I apologize for having trouble with something that must be simple. I'm not sure how to insert/run the module in the query. I created a module and used your suggestion for the field name in the query, but I received the following error "undefined function 'WorkingDays' in expression."
Sorry it has been so long for me to get back with yall on this I have been out for a while.

Jen this may or may not be what you r looking for. I took a random table from a DB I have called Basis and it has a field name called Delivery_Month this is what the SQL would look like.

SELECT WorkingDays([Delivery_Month],Now()) AS NumberOfWeekDays
FROM Basis;

My Basis table has a field in it called Delivery_Month and it is defined as a date field. This will give me the number of working days between the date in the Delivery_Month field and now or today. BTW you could also use date() since Now() provides the time as well and that really isn't needed.
Nov 5 '07 #7
Denburt
1,356 Expert 1GB
Martin, I have no idea why you are having the problem you are having I have used the same table that I used in my last post added the field Delivery_Month to the report. Then in another Text Box I added the following and it seems to work just fine. =WorkingDays([Delivery_Month],Now()) of course again I would use date() just because it is a function designed for returning the date only. The function Now() also returns the time and may cause issues depending on the circumstances.

=WorkingDays([Delivery_Month],Date())
Nov 5 '07 #8

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

Similar topics

2
by: News Central | last post by:
To all! I use the DateDiff function using VB6 and get this error 'Wrong number of argument or invalid property assignment' ... have anyone seen this problem? thanks ....
7
by: Drago | last post by:
Hi, I got the next question, I want to know the diference between two dates and thats is really easy, but my problem is get that diference in the following format ex. "the diference is= 0 year,...
6
by: Lofty | last post by:
Hi all. I have to write an app that interacts with mySQL (I really must have done some evil, evil stuff in a previous life to be landed with this!) I need to work out the difference in days...
1
by: intl04 | last post by:
I'm trying to set up a query that will include a new field ('Days until completion') whose value is derived from the DateDiff function. I think I have the syntax correct but am not sure. Days...
4
by: Paolo | last post by:
I am having some problem with a Year Function. I have form on which I have 4 field which indicate dates and an additional form which sums those dates: These are the fields: YEARS...
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...
5
by: mcbill20 | last post by:
Hello all. I have a really basic question that I hope someone has a better answer for. I apologize in advance-- I know this is probably a really basic question but I am used to Oracle rathern than...
7
by: Adrian | last post by:
I hit on this problem converting a VB.NET insurance application to C#. Age next birthday calculated from date of birth is often needed in insurance premium calculations. Originally done using...
6
by: kevinjwilson | last post by:
I am trying to get the date difference between two dates but I don't want the function to include weekends in the calculation. Does anyone have an idea on how to make this work?
2
by: muddasirmunir | last post by:
i am using vb 6 , i had place two datepicker in form now i want to calcuate differcen of month in two date for this i used the function datediff i had try it withh many syntax but getting error...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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,...

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.