473,803 Members | 3,356 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

DatePart function to display date for Monday and Friday of this week

I'm trying to use DatePart and Datediff functions to show the
formatted m/dd/yyyy display for the dates of Monday and Friday of the
current week. I want it to display as:

Our Weekly Schedule 8/23/2004 thru 8/27/2004:

Can't pinpoint the parameter to check for the current week. Is there a
good reference anywhere to show how to use the methods and such of
both datepart and datediff, or has anyone programmed something similar
prior.
Thanks in advance
Chum
Jul 19 '05 #1
3 4202
Function GetWorkWeekDisp lay()
dtmDate = Date
intDay = DatePart("w",dt mDate)
If intDay < 2 Then
dtmMonday = DateAdd("d",1,d tmDate)
dtmFriday = DateAdd("d",6,d tmDate)
Else
dtmMonday = DateAdd("d",-(6-intDay),dtmDate )
dtmFriday = DateAdd("d",6-intDay,dtmDate)
End If
GetWorkWeekDisp lay = dtmMonday & " thru " & dtmFriday
End Function

dlbjr
Pleading sagacious indoctrination!
Jul 19 '05 #2
"dlbjr" <oo**@iforgot.c om> wrote in message news:<eH******* ******@TK2MSFTN GP10.phx.gbl>.. .
Function GetWorkWeekDisp lay()
dtmDate = Date
intDay = DatePart("w",dt mDate)
If intDay < 2 Then
dtmMonday = DateAdd("d",1,d tmDate)
dtmFriday = DateAdd("d",6,d tmDate)
Else
dtmMonday = DateAdd("d",-(6-intDay),dtmDate )
dtmFriday = DateAdd("d",6-intDay,dtmDate)
End If
GetWorkWeekDisp lay = dtmMonday & " thru " & dtmFriday
End Function

dlbjr
Pleading sagacious indoctrination!


Thanks a ton, worked great!
Jul 19 '05 #3
"dlbjr" <oo**@iforgot.c om> wrote in message news:<eH******* ******@TK2MSFTN GP10.phx.gbl>.. .
Function GetWorkWeekDisp lay()
dtmDate = Date
intDay = DatePart("w",dt mDate)
If intDay < 2 Then
dtmMonday = DateAdd("d",1,d tmDate)
dtmFriday = DateAdd("d",6,d tmDate)
Else
dtmMonday = DateAdd("d",-(6-intDay),dtmDate )
dtmFriday = DateAdd("d",6-intDay,dtmDate)
End If
GetWorkWeekDisp lay = dtmMonday & " thru " & dtmFriday
End Function

dlbjr
Pleading sagacious indoctrination!


I revised the script somewhat to make sure it always displays monday's
and friday's correct date for the current week:

Function GetWorkWeekDisp lay()
dtmDate = Date
intDay = DatePart("w",dt mDate)
If intDay < 2 Then
dtmMonday = DateAdd("d",1,d tmDate)
dtmFriday = DateAdd("d",5,d tmDate)
Elseif intDay = 2 Then
dtmMonday = DateAdd("d",0,d tmDate)
dtmFriday = DateAdd("d",4,d tmDate)
Elseif intDay = 3 Then
dtmMonday = DateAdd("d",-1,dtmDate)
dtmFriday = DateAdd("d",3,d tmDate)
Elseif intDay = 4 Then
dtmMonday = DateAdd("d",-2,dtmDate)
dtmFriday = DateAdd("d",2,d tmDate)
Elseif intDay = 5 Then
dtmMonday = DateAdd("d",-3,dtmDate)
dtmFriday = DateAdd("d",1,d tmDate)
Elseif intDay = 6 Then
dtmMonday = DateAdd("d",-4,dtmDate)
dtmFriday = DateAdd("d",0,d tmDate)
Elseif intDay = 7 Then
dtmMonday = DateAdd("d",-5,dtmDate)
dtmFriday = DateAdd("d",-1,dtmDate)
End If
GetworkweekDisp lay = dtmMonday & " thru " & dtmFriday
End Function
response.write "<font size = 3>" & GetworkweekDisp lay & ""
Jul 19 '05 #4

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

Similar topics

3
6312
by: David | last post by:
Hi Group, i am trying to use the DatePart function on my SQL2000 database. I have a table called visitors with a field called DateTimeEntrance which is filled everytime a visitor enters the site. I am trying to build a stat page where i display the total amount of visitors per day, week, month, year and i can't seem to get the syntax correct. I get an error with the following code: sql = "SELECT * FROM tblVisitors WHERE...
11
5744
by: Matt | last post by:
My ASP page allows the user select the date, and it will display the report during that week of that date. My question is when the program query database, I need to know the beginning date and ending date of that week. Any ideas??
5
7975
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 2005", (or a timestamp that could be formatted). I have been thinking about creating a loop that increases the source date $myDate with 24*60*60 until date("l", $myDate) = "Monday" but maybe I am trying too complicated solutions and overseeing...
3
6942
by: haydn_llewellyn | last post by:
Hi, My company runs on a fiscal calendar that starts on the first monday in July, and is based on a 13 week quarter (4 weeks, 4 weeks, 5 weeks). What I need, is a way of relating Date() to the actual fiscal month (e.g. today is 01/07/05, and is the last day in June in our fiscal calendar). I tried many methods, and had hoped that DatePart() with the 'ww' flag and DatePart() with the 'w' flag (to choose the first monday in July,
1
4868
by: Ryan Ternier | last post by:
I'm trying to find an equivilent function to VB's DatePart function. I have a Year, Month, the Day of week (Sunday, monday etc.) and the week (week 1, week 2) and I need to find the date of that month. Can anyone help me with this? /RT
2
4073
by: Agnes | last post by:
Does .net provide any function for such purpose ? e.g today is 21-10-2004, the week is 43, now I want to get the DATE with (week 42, Monday) Thanks alot
7
2829
by: tasmontique | last post by:
I have an access table that outputs to excel using a query . However what I am trying to do is under the arrival date column specify a criteria based on the Datepart function that only displays output based on specific day of week. I want query to check the stored date in the arrival column and based on that date that is examined by the date part function only return rows based on day of week .Here is my sql. SELECT...
10
17667
by: Mika M | last post by:
Hi! I'm converting some methods of VB-class into C#-class for another project. It's quite easy, but when converting method which returns last week number of the entered year I got problems. The VB code is... Private Function GetLastWeek(ByVal year As Integer) As Integer '// Get last day of the year Dim dte As DateTime = New DateTime(year, 12, 31) '// Return last day weeknumber of the year
1
2018
by: assgar | last post by:
Hi I need help. I know what I want to accomplish, but I do not know how to do it. WHAT I NEED HELP ACCOMPLISHING: How to do I insert data into a table for a date range of two or more months, where every second or third week should be able to have different events/appointments.
0
9703
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10555
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10069
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9127
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7607
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5636
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4277
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 we have to send another system
2
3802
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2974
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.