473,405 Members | 2,185 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,405 software developers and data experts.

calculate Monday's date

Does anyone know how to give a date (not today's date) and have the program
calculate the previous monday's date from it? Any help would be appreciated.
Thanks!!!!

Joe
Aug 3 '05 #1
2 2018
The DateTime object as a DayOfWeek property. Just keep subtracting 1 day
from the date and check that property. Once you hit Monday, you are done.

"Joecx" <Jo***@discussions.microsoft.com> wrote in message
news:AE**********************************@microsof t.com...
Does anyone know how to give a date (not today's date) and have the
program
calculate the previous monday's date from it? Any help would be
appreciated.
Thanks!!!!

Joe

Aug 3 '05 #2
Joe,
As Marina I normally subtract the difference between your desired Date's day
of week & Monday's day of week.

Something like:

Public Function MondayBefore(ByVal day As DateTime) As DateTime
Dim days As Integer = day.DayOfWeek - DayOfWeek.Monday
If days < 0 Then
days += 7
End If
Return day.Date.Subtract(TimeSpan.FromDays(days))
End Function

Then you can call it passing in any date you want:

Debug.WriteLine(MondayBefore(DateTime.Now))
Debug.WriteLine(MondayBefore(#12/25/2005#))
Hope this helps
Jay

"Joecx" <Jo***@discussions.microsoft.com> wrote in message
news:AE**********************************@microsof t.com...
| Does anyone know how to give a date (not today's date) and have the
program
| calculate the previous monday's date from it? Any help would be
appreciated.
| Thanks!!!!
|
| Joe
Aug 3 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
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 -...
5
by: Martien van Wanrooij | last post by:
I would like to retrieve, let us say, the First Monday after a certain date, so my (imaginary) function could be something like echo weekdayAfter("28 July 2005", "Monday") should return "1 August...
2
by: Rustan | last post by:
Hi Im using GregorianCalendar to find out the current years week numbers. When the user chooses a week number in a dropdown i want to show that week in a table with the corresponding dates. For...
3
by: | last post by:
Hello, I am hoping someone else has thought about a date time calculation i need to perform. I would like to be able to calculate the number of "working minutes" between 2 dates, given my...
2
by: Joecx | last post by:
Does anyone know how to give a date (not today's date) and have the program calculate the previous monday's date from it? Any help would be appreciated. Thanks!!!! Joe
5
by: cvisal | last post by:
Hi all Im working on productivity calculations (Time calculations) and need some help in coding. Database Tool:MS-Access 2003. The general operator punch-in time is 5:30 AM and the punch-out...
5
by: Chris | last post by:
I am trying to output Monday of the current week i.e. if Monday is the 8th I want to display 'Monday 8th' for any date between Monday 8-14th. I would appreciate any help, the code below is...
4
by: Vince | last post by:
Given a week Number, how do I calculate the date that for the Monday of that week?
2
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
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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...
0
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
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...

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.