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.
 

Some videos you may like

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.

Arithos

Well-known Member
Joined
Aug 14, 2014
Messages
598
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"
 

NeonRedSharpie

Well-known Member
Joined
Jul 14, 2014
Messages
1,678
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.
 

Arithos

Well-known Member
Joined
Aug 14, 2014
Messages
598
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")
 

yoan6

New Member
Joined
Jul 1, 2014
Messages
27

ADVERTISEMENT

My esxpected result is 17:15
 

yoan6

New Member
Joined
Jul 1, 2014
Messages
27

ADVERTISEMENT

OK. I will have a look and I will keep you updated.
 

yoan6

New Member
Joined
Jul 1, 2014
Messages
27
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?
 

Joe4

MrExcel MVP, Junior Admin
Joined
Aug 1, 2002
Messages
54,459
Office Version
  1. 365
Platform
  1. Windows
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)
 

Watch MrExcel Video

Forum statistics

Threads
1,109,050
Messages
5,526,494
Members
409,704
Latest member
saialkesh

This Week's Hot Topics

Top