473,504 Members | 13,830 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how to calculate the date difference without including sunday

chandru8
145 New Member
can any one tell how to do it
iam tried like this but getting answer with including sunday
DateDiff("d","23/02/2008","16/04/2008")
as 53
thanks
Apr 16 '08 #1
3 3399
debasisdas
8,127 Recognized Expert Expert
find out the number of sundays in the time period and substract from the total numer of days.
Apr 16 '08 #2
chandru8
145 New Member
hi
i have tried like this
but this loop works for a month only
if need to calculate for more than 2 months its not working
for ex:
dt = 23/02/2008
todays date
its not working

For i = Format(dt, "dd") To Format(Date, "DD")

If Format(dt, "DDDD") = "Sunday" Then

ii = ii + 1

End If
dt = DateAdd("d", 1, dt)

Next i
Apr 17 '08 #3
smartchap
236 New Member
I think following code will do:

'To find out No. of days between two dates excluing No. of Sundays in between them:

Dim StartDay As String

Private Sub Command1_Click()
If Me.DTPicker1.Value > Me.DTPicker2.Value Then
MsgBox "Please select Date FROM which is earlier than Date TO."
Exit Sub
End If
'StartDay = "vb" & Format(Me.DTPicker1.Value, "dddd") 'Used DTPicker3
StartDay = "vb" & Format(Me.DTPicker3.Value, "dddd")
start = Switch(StartDay = "vbSunday", 0, StartDay = "vbMonday", 1, StartDay = "vbTuesday", 2, StartDay = "vbWednesday", 3, StartDay = "vbThursday", 4, StartDay = "vbFriday", 5, StartDay = "vbSaturday", 6)
d = DateDiff("d", Me.DTPicker1.Value, Me.DTPicker2.Value, start)
'w = DateDiff("w", Me.DTPicker1.Value, Me.DTPicker2.Value, Start)
w = Fix(d / 7)
w1 = d - w * 7
If w1 <> 0 And d >= 7 Then w = w + 1 'if selcted more than 7 days and not full weeks then
Text1.Text = d - w
'MsgBox Day(Me.DTPicker2.Value)
'Text2.Text = Format(Me.DTPicker2.Value, "dddd") ' dd/mm/yyyy")'it is like Sunday or Monday etc.

End Sub

Private Sub DTPicker1_Change()
DTPicker3.Year = Me.DTPicker1.Year
Me.DTPicker3.Month = Me.DTPicker1.Month
Me.DTPicker3.Day = 1
'so that we can find out the first day of month in DTPicker1 from where we want
'to calculate the no. of days upto DTPicker2 (excluding Sundays).
End Sub

Private Sub Form_Load()
Text2.Visible = False
'During loading set DTPicker3 date as 1st of the month in DTPicker1.
DTPicker3.Year = Me.DTPicker1.Year
Me.DTPicker3.Month = Me.DTPicker1.Month
Me.DTPicker3.Day = 1
Me.DTPicker3.Visible = False
Command1_Click 'so that on loading No. of Days is shown.
End Sub

Always Believe in GOD!
Apr 19 '08 #4

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

Similar topics

3
17902
by: CrystalDBA | last post by:
I am using SQL Server 2000. I need to query my database for all the contracts that came in during a certain time frame (user is prompted for reportingperiodid). Table - Periods Fields -...
26
4370
by: Frank | last post by:
For my website i would like to display the age of my son in years, months, days and hours. For now i manage to get a result for totals. Like the total number of days. This is the beginning: ...
3
11322
by: Craig Bates | last post by:
Hi Guys I have recently been learning SQL from a book whose examples used the Oracle engine. I have now made an Access database containing information for English Football fixtures. I am using...
5
40649
by: Hardy Wang | last post by:
Hi: Are there any algorithms I can use, that based on a given date and a culture code (different cultures may have different beginning of week), I can get first and last date of the current week?...
9
3227
by: griemer | last post by:
Hi every one, Is there a way to calculate the timestamp of 00:00:00 last Sunday. For me, this is the begin of the current week.. Or, how old is this week, in seconds Any ideas? Regards,
32
3390
by: barkarlo | last post by:
In my table date/time field (starttime,endtime) include both date and time. How can I calculate worktime in query for each employee who works sundays? for an example: sometimes starttime and...
2
1936
by: Mike | last post by:
Is there a way to calculate the total number of weekdays when provided a date? Example: If I have a start date of 7/11/2008 and I want to go out 10 days, I want to get this: 6 weekdays 4...
15
6398
by: student4lifer | last post by:
Hello, I have 2 time fields dynamically generated in format "m/d/y H:m". Could someone show me a good function to calculate the time interval difference in minutes? I played with strtotime() but...
2
2321
by: shimul | last post by:
Hi All, If I set up a form with start date (choose from calendar) and end date. Each week Start date (Monday ) and want to automatically calculate end date (sunday each week) . how can I...
0
7098
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
7366
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7017
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...
0
7471
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5610
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,...
0
4698
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...
0
1526
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 ...
1
754
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
406
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...

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.