473,382 Members | 1,545 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,382 software developers and data experts.

Week Ending

Hi Guys,

I was wondering if anyone could help me find a function to get a week
ending function??

i.e. week ending on sunday

Therefore if a i was to input todays date in my function it would
output the sunday date of the same week. If anyone has a such a
function or can point me in the right direction it would be most
helpful.

Regards

CG

Jul 25 '06 #1
4 2130
You can use the 'DayOfWeek' Property of the Date type to figure out the day
of today
Today.DayOfWeek will return an enum value that you can calculates the next
Sunday based on that

hth,
Samuel Shulman

"csgraham74" <cs********@gmail.comwrote in message
news:11**********************@b28g2000cwb.googlegr oups.com...
Hi Guys,

I was wondering if anyone could help me find a function to get a week
ending function??

i.e. week ending on sunday

Therefore if a i was to input todays date in my function it would
output the sunday date of the same week. If anyone has a such a
function or can point me in the right direction it would be most
helpful.

Regards

CG

Jul 25 '06 #2
Use the DayOfWeek property to determine the current day, convert it to
an integer, and use it to calculate how many days you have to add to get
to the end of the week.

E.g. if Wednesdays has the value 3 (not sure, you have to check that),
then you would add 7 - 3 = 4 days to get to sunday.

csgraham74 wrote:
Hi Guys,

I was wondering if anyone could help me find a function to get a week
ending function??

i.e. week ending on sunday

Therefore if a i was to input todays date in my function it would
output the sunday date of the same week. If anyone has a such a
function or can point me in the right direction it would be most
helpful.

Regards

CG
Jul 25 '06 #3
Try this:

Private Function GetLastDayOfWeek(ByVal dt As Date) As Date
Dim firstDayOfWeek As Integer =
CInt(DateTimeFormatInfo.CurrentInfo.FirstDayOfWeek )
Dim lastDayOfweek As Integer = (firstDayOfWeek + 6) Mod 7

If lastDayOfweek < dt.DayOfWeek Then
Return dt.AddDays(lastDayOfweek - dt.DayOfWeek + 7.0)
Else
Return dt.AddDays(lastDayOfweek - dt.DayOfWeek)
End If
End Function

/claes

"csgraham74" <cs********@gmail.comwrote in message
news:11**********************@b28g2000cwb.googlegr oups.com...
Hi Guys,

I was wondering if anyone could help me find a function to get a week
ending function??

i.e. week ending on sunday

Therefore if a i was to input todays date in my function it would
output the sunday date of the same week. If anyone has a such a
function or can point me in the right direction it would be most
helpful.

Regards

CG

Jul 26 '06 #4
Thanks guys you help had been greatly appreciated

CG
Claes Bergefall wrote:
Try this:

Private Function GetLastDayOfWeek(ByVal dt As Date) As Date
Dim firstDayOfWeek As Integer =
CInt(DateTimeFormatInfo.CurrentInfo.FirstDayOfWeek )
Dim lastDayOfweek As Integer = (firstDayOfWeek + 6) Mod 7

If lastDayOfweek < dt.DayOfWeek Then
Return dt.AddDays(lastDayOfweek - dt.DayOfWeek + 7.0)
Else
Return dt.AddDays(lastDayOfweek - dt.DayOfWeek)
End If
End Function

/claes

"csgraham74" <cs********@gmail.comwrote in message
news:11**********************@b28g2000cwb.googlegr oups.com...
Hi Guys,

I was wondering if anyone could help me find a function to get a week
ending function??

i.e. week ending on sunday

Therefore if a i was to input todays date in my function it would
output the sunday date of the same week. If anyone has a such a
function or can point me in the right direction it would be most
helpful.

Regards

CG
Jul 31 '06 #5

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

Similar topics

5
by: Bullschmidt | last post by:
If I know the week number and the year, how can I calc the beginning and ending dates of the week? For background I'm going to do some grouping by week but don't just want to call the weeks Week...
9
by: Ray | last post by:
I need to convert the normal calendar to show the week no., the period no. and the financial year. The financial year format is as follows:- Date start: 2 May, 2005 7 days a week, 4 weeks a...
3
by: Matt | last post by:
Given a date, how to find the beginning date and ending date of that week please advise!
3
by: apartain | last post by:
I use DatePart("ww",.Date) to get the number of the week in the year for a weekly time card. The week in the system is beginning Sunday and ending Saturday. Is there any way to make it beginning...
3
by: Mike Orr | last post by:
What's the best way to summarize data by week? I have a set of timestamped records, and I want a report with one row for each week in the time period, including zero rows if there are weeks with...
7
by: derekdeben | last post by:
Hi, I have created a report that totals the number of days it took a product to ship by percentage by a date range for a specific location. My data comes from a query with the following headers: ...
3
by: sbaird | last post by:
Aloha from Hawaii, I'm beating my head on the wall here. I have a recruiting contact managment database I'm trying to create. Managers (there ar 14 of them) have to make a certain number of...
5
slifland
by: slifland | last post by:
I am trying to make a appointment book for a access 2003 database. I would like the report to display the title "Appointments for "month day" - "month day" "year" What I have so far doesn’t do...
0
by: jmarcrum | last post by:
Hi all, I have an excel spreadsheet that in column A, has a formula under the first row in A2 that automatically calculates the Week-ending date when someone starts typing something in cells B2,...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

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.