473,513 Members | 2,616 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Week date

If I have week number for example: 24
how can I get start(monday) and end(sunday) date?

Thank you,
Simon
Nov 20 '05 #1
2 1291
simon,

i'm not sure if there's a built-in funtionality
in .net to solve your problem. in case there's none, you
can try this one.

Dim dt as new DateTime
(DateTime.Now.Year,1,1)
Dim week_number as Integer = 1 'change
week number
Dim days_in_week as Integer = 7
Dim start_date as String
Dim end_date as String
dt = dt.AddDays(( (week_number-1) *
days_in_week) - 1)

While ((dt.DayOfWeek <> DayOfWeek.Monday))
dt = dt.AddDays(-1)
End While

start_date = dt.ToShortDateString()
end_date = dt.AddDays(days_in_week-
1).ToShortDateString()

Console.WriteLine("Start: {0} | End:
{1}",start_date, end_date)

HTH

gani
http://thedeveloperscorner.com.ph
-----Original Message-----
If I have week number for example: 24
how can I get start(monday) and end(sunday) date?

Thank you,
Simon
.

Nov 20 '05 #2
Gani,
That's about what I was going to say.

However you don't really need the While loop, you can use:

dt = dt.AddDays(dt.Monday - dt.DayOfWeek)

To get the same effect.

Hope this helps
Jay

"gani" <g@g.com> wrote in message
news:1a*****************************@phx.gbl...
simon,

i'm not sure if there's a built-in funtionality
in .net to solve your problem. in case there's none, you
can try this one.

Dim dt as new DateTime
(DateTime.Now.Year,1,1)
Dim week_number as Integer = 1 'change
week number
Dim days_in_week as Integer = 7
Dim start_date as String
Dim end_date as String
dt = dt.AddDays(( (week_number-1) *
days_in_week) - 1)

While ((dt.DayOfWeek <> DayOfWeek.Monday))
dt = dt.AddDays(-1)
End While

start_date = dt.ToShortDateString()
end_date = dt.AddDays(days_in_week-
1).ToShortDateString()

Console.WriteLine("Start: {0} | End:
{1}",start_date, end_date)

HTH

gani
http://thedeveloperscorner.com.ph
-----Original Message-----
If I have week number for example: 24
how can I get start(monday) and end(sunday) date?

Thank you,
Simon
.

Nov 20 '05 #3

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

Similar topics

2
5200
by: androtech | last post by:
Hello, I'm looking for a function that returns a date range for a specified week number of the year. I'm not able to find functions like this anywhere. Any pointers/help would be much appreciated. TIA
7
15137
by: Shuffs | last post by:
Could someone, anyone please tell me what I need to amend, to get this function to take Sunday as the first day of the week? I amended the Weekday parts to vbSunday (in my code, not the code attached), yet when I ran it for 28/09/2003 (UK date format) it returned Week 39. I would have expected it to return Week 40. However, I'm really stuck...
14
5083
by: deko | last post by:
This runs, but does not narrow to current week. suggestions appreciated! SELECT lngEid, dtmApptDate, Subject, Appt_ID FROM qry002 WHERE (dtmApptDate BETWEEN DateAdd("d",-weekday()+2,) And DateAdd("d", 6, DateAdd("d", -weekday()+2,)))
9
3398
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 period and 13 periods a year. normally 52 weeks per year but one 53-week a year every 6 years. The 53th week is included in period 13. Can someone...
3
5923
by: Matt | last post by:
Given a date, how to find the beginning date and ending date of that week please advise!
0
2834
by: Lee Harr | last post by:
I wrote a function to return the first date of a given week (and a few related functions) : -- return the first date in the given week CREATE or REPLACE FUNCTION week_start(integer, integer) RETURNS date AS ' DECLARE pyear ALIAS FOR $1; pweek ALIAS FOR $2;
14
3472
by: Tina | last post by:
My employer tracks productivity/performance of clinicians (how much they bill) each week, its averages for the month, and the 6 months. These averages are compared to their expected productivity. However, the expectation changes - it may be 60% for a while, then change to 50%. Initially, I was averaging the expectation, along with the...
6
25349
by: aarklon | last post by:
Hi folks, I found an algorithm for calculating the day of the week here:- http://www.faqs.org/faqs/calendars/faq/part1/index.html in the section titled 2.5 what day of the week was 2 august 1953 I checked the algorithm it is very correct.
5
13700
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 heading in the right direction but doesn't quite give me the results I am looking for. $givenday = mktime(0,0,0,10,08,2007); $Monday =...
4
10036
by: Charlotte | last post by:
Hi, is it possible to determine the first and the last day of a week (with classic ASP) nu = "06/01/2008" week = (DatePart("ww",nu)) firstday = dateadd("d",(-datepart("w",date())),nu) lastday = dateadd("d",(7-datepart("w",date())),nu)
0
7270
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...
0
7178
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7397
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. ...
0
7563
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7125
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
4757
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3252
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3239
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
470
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...

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.