How to get week start date, End date for a given week nunber,year?

I want  a javascript function to to get the starting date and end date of a week when I have given the week number (1 to 5), Month number (1 to 12), valid year as parameter. How to do that?


Manivannan
0
manivannan_ser
4/8/2008 6:46:25 AM
asp.net.client-side 24353 articles. 2 followers. Follow

5 Replies
1542 Views

Similar Articles

[PageSpeed] 30

 You can visited http://www.datejs.com/2007/11/

I dont have example.

Hope it's help you.

0
codingvn
4/8/2008 8:36:23 AM

try this example

function GetWeekStartEndDate(){
    var week = 5;
    var month = 4;
    var year = 2008;
   
    var PositiveOneDay = new Date(new Date('1/2/2000') - new Date('1/1/2000'));
    var NegetiveOneDay = new Date(new Date('1/1/2000') - new Date('1/2/2000'));      
    var dt , stDate , endDate
          
    if (week == 1)
        dt = new Date(month + '/1/' + year);
    else if (week == 5)
        dt = new Date(month + '/28/' + year);
    else
        dt = new Date(month + '/' + (week * 7) + '/' + year);
   
    stDate = dt;
    endDate = dt;
    //Get Start date
    while (stDate.getDay() != 1)
    {
        stDate = new Date(stDate - PositiveOneDay);
    }
    //Get End date
    while (endDate.getDay() != 0)
    {
        endDate = new Date(endDate - NegetiveOneDay);
    }       
    alert('Starting date of a week : ' + stDate.toString());
    alert('Ending date of a week : ' + endDate.toString());
}

0
d_dalapati
4/8/2008 9:23:50 AM

Thanks. Its working fine


Manivannan
0
manivannan_ser
4/8/2008 1:00:07 PM

Hi dalapati!

 

A small modification I need. The starting day is monday as usual. But the end day will be friday and if a month does not contain more than 4 or 5 weeks it should give an alert.

Thanks in advance 


Manivannan
0
manivannan_ser
4/8/2008 2:51:18 PM

manivannan_ser:
Hi dalapati!
A small modification I need. The starting day is monday as usual. But the end day will be friday and if a month does not contain more than 4 or 5 weeks it should give an alert.

Thanks in advance 

Previous script was slightly wrong. I have modified the script. Try it now

function GetWeekStartEndDate(){
    var week = 5;
    var month = 2;
    var year = 2002;
   
    var PositiveOneDay = new Date(new Date('1/2/2000') - new Date('1/1/2000'));
    var NegetiveOneDay = new Date(new Date('1/1/2000') - new Date('1/2/2000'));      
    var dt , stDate , endDate
    //Get first day of month
    dt = new Date(month + '/1/' + year);
    //Seek to intended week
    var i = 1;
    for(i = 1 ; i < (week-1)*7 ; i++){
        dt = new Date(dt - NegetiveOneDay);
    }  
    //if found date is week end get immediate next week start date
    while (dt.getDay() == 0 || dt.getDay() == 6){
        dt = new Date(dt - NegetiveOneDay);
    }   
    //if found date is in next month then invalid input
    if (dt.getMonth() == month - 1){
        stDate = dt;
        endDate = dt;
        //Seek to week start date
        while (stDate.getDay() != 1)
        {
            stDate = new Date(stDate - PositiveOneDay);
        }
        //Seek to week end date
        while (endDate.getDay() != 5)
        {
            endDate = new Date(endDate - NegetiveOneDay);
        }
                      
        alert('Starting date of a week : ' + stDate.toString());
        alert('Ending date of a week : ' + endDate.toString());
    }      
    else{
        alert('Invalid Input');
    }   
}

0
d_dalapati
4/9/2008 4:22:42 AM
Reply:

Similar Artilces:

Getting Week Start and End Dates
I was wondering if anybody know a better way to write the code that i have below. what i am trying to accomplish is that the user clicks a button and that will select the current monday and friday date so that i can use that to run the report. I cam up with this bc of my lack of knowledge doing this sort of thing. ThanksString bDate; String eDate;String WeekDay; WeekDay = DateTime.Today.DayOfWeek.ToString();if (WeekDay.CompareTo("Monday") == 0) {bDate = DateTime.Today.ToShortDateString();eDate = DateTime.Today.AddDays(4).ToShortDateString(); }else if (WeekDay.CompareTo(&quo...

how to find the week end date (saturday & sunday) given current date ?
In ASP.NET scripts: I have today's date as input, i need to get the date of coming saturday and sunday's date and pass this date to T-SQL as a parameter to get the events in the week ends. I want to do this  without using event calendar. All events has the start date and end date associated with it. any suggestions ? more info: user clicks the link of Week end events => then i want to get the date of week end date. => pass it to t-sql => get the events on this date. If you are using SQL Server then I would strongly recommend using a calendar table. I would take time ...

Get Friday end of the week date for the fiscal year
I am trying to feed into dropdown a list of all Fridays for the current fiscal year, eg.  Dropdown for user to select: Septemer 5, 2008 September 14, 2008 September 20, 2008 September 27, 2008 etc.  I am not sure if there is a function I could use and how to generate those values.  I am using C# and SQL database. Your assistance or direction will be appreciated.         Anna-Maria Here's an example for you to play with. If you run it as is, you'll see the output. Just make the necessary changes to have it work for you. &nbs...

r31680 -[S32/Temporal] Added to Date: "There are also C<week>, C<week-year>, C<week-number>, C<weekday-of-month>, and C<day-of-year> methods, which work just like their DateTime equivalents."
Author: Kodi Date: 2010-07-14 16:35:46 +0200 (Wed, 14 Jul 2010) New Revision: 31680 Modified: docs/Perl6/Spec/S32-setting-library/Temporal.pod Log: [S32/Temporal] Added to Date: "There are also C<week>, C<week-year>, C<week-number>, C<weekday-of-month>, and C<day-of-year> methods, which work just like their DateTime equivalents." Modified: docs/Perl6/Spec/S32-setting-library/Temporal.pod =================================================================== --- docs/Perl6/Spec/S32-setting-library/Temporal.pod 2010-07-14 14:35:21 UTC (rev 316...

calendar date span (date start : date end)
Hi! Can anyone help me with this? Say, I have these two textboxes. Date Start:        Date End:             What I wanted to do is to put dates on it using the calendar. My problem is I do not know what to do to keep the "Date Start" not way after the set "Date End", and for "Date End" not way before the set "Date Start".   example: Date Start: July 1, 2008              &nb...

How can i get the dates for each day of the week from the week number
Hi GUys Im a newbie using vs2005, vb.net .net2.0 I am using this code to get the week number Dim weekNum As Integer = DatePart(DateInterval.WeekOfYear, Date.Now, Microsoft.VisualBasic.FirstDayOfWeek.Monday, FirstWeekOfYear.FirstFullWeek) week.Text = weekNum.ToString Basically i am displaying the week numbers in a dropdown list and i want to now get the dates for each day of week based on the selected week number in my dropdown list, ie mondays date = bla, tuesday date = bla. Im not very good with the date stuff and could use some help on how to do thisThanks and Kind Regards &nb...

how to store weeks and dates of week in a table in vb.net
 I have a web form in vb.net 1.1 , i want to select user name , month , year  from drop down with respect to that month i want to display weeks of the month like week 1 week 2 , week 3 ... so on for selected month & year  Problem :: i have got the firstday , last day , totalno of days in the month but don't know how to move forward after i am able to display the weeks list then on selection of a particular week i want to dispaly data for that week day wise in grid so need to maintain a the dated with week no , but not getting the way how to do it  kindly guide &nb...

How to get week number in a given date
Dear All, Is there any mathod in powerbuilder to get week number of the given date. With thanks Polachan ---== Posted via the PFCGuide Web Newsreader ==--- http://www.pfcguide.com/_newsgroups/group_list.asp Hi Polachan; FYI: The PFC has a NVUO object (pfc_n_cst_datetime) that has a WeekNumber method that would return that for you. If you are not using the PFC you can still transform the code segment into your application. HTH -- Regards ... Chris ISUG - NA RUG Director http://chrispollach.pbdjmagazine.com "POLACHAN" <polachanpp@yahoo.com&g...

how to get day or date for a given week
  consider i have week from 1 to 52 in a combobox for a year. if i select any week, it should bring the days or date for that specific week. is it possible to get it ?  anyone pls give me sample code. thanks in advance ASPX Select Week: <asp:dropdownlist id="DropDownList1" runat="server" autopostback="True" onselectedindexchanged="DropDownList1_SelectedIndexChanged"> <asp:listitem></asp:listitem> </asp:dropdownlist> CODE-BEHIND protected void Page_Load(object sender, EventArgs e) { if (!this.I...

Generating week dates based on choice of year and week from dropdowns
 Hi I am very new to all this programming stuff:P I was wondering if it is possible to generate a week (monday-sunday) with the right dates based on the choices made in 2 dropdown lists? I imagine that the week will be display in a gridview. The first dropdown you choose a week and the other one you choose the year. Any help would be welcome:) thanksMichael Have a look at this thread: http://forums.asp.net/p/884219/1187299.aspx#1187299 You can easily modify it to display 7 days.  public static DateTime GetLastOccurenceOfDay(DateTime value, DayOfWeek dayOfWeek) { ...

How can I get the number of week (of year) in a Date ...
from PB ?? In ASA I can make : SELECT FIRST_DATE = WEEKS ( '2002-01-01' ) , MY_DATE = WEEKS ( '2002-01-07' ) , WEEK = ( WEEKS ( '2002-01-24' ) - WEEKS ( '2002-01-01' ) ) + 1 FROM ANA_OGG ; How can I make it from a PB function ?? TNX hi if you're programming with pfc you can use the function of_weeknumber. you find it in the n_cst_datetime service... cheers michael "Mirko Di Tommaso" <mirko.ditommaso@ilmessaggero.it> wrote in message news:gLfo1#fFCHA.247@forums.sybase.com... > from PB ?? >...

[Help!] Calculate Week of Year by given a Date
Hi, I want to calculate the Week of the Year by given a Date. For Example: Date given is current date. DateTime.now the week of the year should be 51th weeks seems assume the start date of the year is 1st Feb. So how i going to program it in ASP.NET C#? Thanks. If you are speaking of fiscal weeks, then you are going to have to build a class that creates this.  I wish the datetime class had the logic for this built in but it doesn't.   You have to google the formula for finding the fiscal week of a year, which is not as easy as it sounds since the first day of the fiscal...

Dates, Dates, Dates!
Hello all... I am in the process of building an appointment system, and I am trying to see if I can get some pointers on which way to go on this. The first version of this appointment system was very lo-tech, and it stored all of the possible dates/times in the database. Once a user booked an appointment, their information was logged to that date/time, and then that date/time would no longer show in the list of possible openings. This was great for a temporary fix, but with having to pre-populate all of the dates/times, the system would eventually have to be updated to continue on pa...

Start date and End Date
Hi, Working on a create user workflow i need to add a mandatory start date for the user and an optional end date for some users. I have two fields for this in the request form of type date and control Type is DatePicker. There is an eDirectory attribute called loginActivationTime, is that used for activating an account at the preset time? End date, is that Login Expiration Time ? And I think I have to repormat the dates as well ? I have found some discussions about date formats but what is the best practice on how to do a reformat if I use IDM 3.6 and UA3.6.1 ? I guess I...

Web resources about - How to get week start date, End date for a given week nunber,year? - asp.net.client-side

Questions and Answer - FunTrivia.com : Archive 77
Questions From Sep 06 03 38502. Who was Echo? 38503. Much of the early action in which US spin-off series was set in Seaview Circle? 38504. ...

Parks & Recreation Cancelled Or Renewed? - TVbytheNumbers
Posts Tagged ‘Parks & Recreation Cancelled Or Renewed?’ April 7th, 2015 at 8:09 am NBC Predictions: 'A.D.: The Bible Continues' Starts As Likely ...

German secret service 'spied on Clinton': report
The German secret service listened in on at least one of Hillary Clinton's telephone calls when she was US secretary of state, German media reported ...

X Factor Finals
View mobile site HuffPost's QuickRead... Loading... TV UK NEWS iOS app Android app More Log in Create Account Notifications Profile Settings ...

Open Farm Sunday
View mobile site HuffPost's QuickRead... Loading... UK NEWS wales iOS app Android app More Log in Create Account Notifications Profile Settings ...

81 Million People Were Reached By Apple's Free U2 Album
Remember that time Apple gave everyone a free copy of U2's latest album 'Songs of Innocence'? Well It looks like the figures are in and staggeringly, ...

Base Jumpers Land In Rooftop Pool Party In Kuala Lumpur
Now this is how you make an entrance... Jumping off the Kuala Lumpur Tower 335 meters up, these three daredevils made the arrival of a lifetime ...

Scotland's Referendum: Pictures, Videos, Breaking News
Big News on Scotland's Referendum. Includes blogs, news, and community conversations about Scotland's Referendum.

Open Farm Sunday
View mobile site HuffPost's QuickRead... Loading... UK NEWS wales iOS app Android app More Log in Create Account Notifications Profile Settings ...

Resources last updated: 11/28/2015 9:11:01 AM