Compare two dates

yoan6

New Member
Joined
Jul 1, 2014
Messages
27
Hi,

I would like to know How I can compare the two dates below.

Date1: 21/08/2014 17:05:01
Date2: 22/08/2014 10:20:52

I try to use NETWORKDAYS(Date1,Date2) but I do not have the good result.
I also try to do Date2-Date1. I do not realy have the good result because the result contain the weekend days and I need only the workdays.

Do you have an idea how I can do this in vba?


Thank you.
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
if you just want to compare them you can do this.

=IF(WEEKDAY(Date1)=WEEKDAY(Date2),"They are the same","They are not the same")

If its two mondays, it will return "They are the same"
 
Upvote 0
What is your expected result? What is the result you are getting? Using networkdays() you should get two for this because there are two workdays.
 
Upvote 0
This will inform you if the date in question is a saturday or sunday.

=IF(OR(WEEKDAY(Date1)=1,WEEKDAY(Date1)=7),"Its a weekend";"Its a Workday")
 
Upvote 0
Thanks Joe4. It works in the file but not in VBA.

Code:
=NETWORKDAYS(A104904;IF(A107967="";NOW();A107967))+NETWORKDAYS(IF(A107967="";NOW();A107967);IF(A107967="";NOW();A107967))*(MOD(IF(A107967="";NOW();A107967);1)-1)-NETWORKDAYS(A104904;A104904)*MOD(A104904;1)

The main issue is the MOD function that does not work in VBA.

Do you know how I can convert it in vba?
 
Upvote 0
The main issue is the MOD function that does not work in <acronym title="visual basic for applications" style="border-width: 0px 0px 1px; border-bottom-style: dotted; border-bottom-color: rgb(0, 0, 0); cursor: help; color: rgb(51, 51, 51); background-color: rgb(250, 250, 250);">VBA</acronym>.
The MOD function does work in VBA, it is just structured differently. See: Mod Operator (Visual Basic)

You can also use NETWORKDAYS in VBA by prefacing it with WorksheetFunction. See: WorksheetFunction.NetworkDays Method (Excel)
 
Upvote 0

Forum statistics

Threads
1,213,536
Messages
6,114,205
Members
448,554
Latest member
Gleisner2

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top