This is a migrated thread and some comments may be shown as answers.

Date Picker

7 Answers 78 Views
Calendar
This is a migrated thread and some comments may be shown as answers.
bEnDi
Top achievements
Rank 2
bEnDi asked on 26 Sep 2008, 01:50 AM
Hi All,

Is there anyway that i could grap the number of weeks from the date picker to a textbox or anything??? Is there anyway(code..etc?) that i could do it??


Thanks

7 Answers, 1 is accepted

Sort by
0
Missing User
answered on 26 Sep 2008, 07:42 AM
Hello Lendi,


To see more information on the requested functionality, please refer to the following article.
Getting and Setting Values


All the best,
Plamen
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
bEnDi
Top achievements
Rank 2
answered on 26 Sep 2008, 07:53 AM
Hi,
I think you don't get what i mean. For example, the last week in December is 52th so i want to grap that 52 into a textbox. All i want is to convert datetime.now to the number of week. Example 29.12.2008 is 52. In other works i want the business/work week number.

Thanks
0
Missing User
answered on 26 Sep 2008, 10:21 AM
Hi Lendi,



The following code example demonstrates how to calculate the number of weeks from the date picker:


<%@ Page Language="C#" %> 
 
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %> 
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"
<head runat="server"
    <title>Untitled Page</title> 
</head> 
<body> 
    <form id="form1" runat="server"
        <asp:ScriptManager ID="ScriptManager1" runat="server" /> 
        <div> 
            <script type="text/javascript"
             
            // Code to calculate Eur weeknumber 
            function getWeekEUR(day, month, year)  
            { 
                year = y2k(year); 
                var when = new Date(year,month,day); 
                var newnewYear = new Date(year,0,1); 
                var modDay = newYear.getDay(); 
                if (modDay == 0) modDay=6; else modDay--; 
 
                var daynum = ((Date.UTC(y2k(year),when.getMonth(),when.getDate(),0,0,0) - 
                             Date.UTC(y2k(year),0,1,0,0,0)) /1000/60/60/24) + 1; 
 
                if (modDay < 4 ) { 
                    var weeknum = Math.floor((daynum+modDay-1)/7)+1; 
                } 
                else { 
                    var weeknum = Math.floor((daynum+modDay-1)/7); 
                    if (weeknum == 0) { 
                        year--; 
                        var prevNewYear = new Date(year,0,1); 
                        var prevmodDay = prevNewYear.getDay(); 
                        if (prevmodDay == 0) prevmodDay = 6; else prevmodDay--; 
                        if (prevmodDay < 4weeknum = 53; else weeknum = 52
                    } 
                } 
 
                return + weeknum; 
            } 
            // End Eur weeknumber 
             
            // Code to calculate week number 
            function getWeek(day, month, year)  
            { 
                year = y2k(year); 
                var when = new Date(year,month,day); 
                var newnewYear = new Date(year,0,1); 
                var offset = 7 + 1 - newYear.getDay(); 
                if (offset == 8) offset = 1
                var daynum = ((Date.UTC(y2k(year),when.getMonth(),when.getDate(),0,0,0) - Date.UTC(y2k(year),0,1,0,0,0)) /1000/60/60/24) + 1; 
                var weeknum = Math.floor((daynum-offset+7)/7); 
                if (weeknum == 0) { 
                    year--; 
                    var prevNewYear = new Date(year,0,1); 
                    var prevOffset = 7 + 1 - prevNewYear.getDay(); 
                    if (prevOffset == 2 || prevOffset == 8) weeknum = 53; else weeknum = 52
                } 
                return weeknum; 
            } 
             
            function y2k(number) { return (number < 1000) ? number + 1900 : number; } 
 
 
            // End code to calculate week number 
             
            function ValueChanged(sender, args) 
            { 
                var radTextBox1 = $find("<%= RadTextBox1.ClientID %>"); 
                var radTextBox2 = $find("<%= RadTextBox2.ClientID %>"); 
                             
                if (!args.get_newDate()) 
                { 
                    radTextBox1.clear(); 
                    radTextBox2.clear();     
                    return; 
                }                     
                     
                var usWeek = getWeek
                    args.get_newDate().getDate(), 
                    args.get_newDate().getMonth(), 
                    args.get_newDate().getYear()); 
                     
                var eurWeek = getWeekEUR
                    args.get_newDate().getDate(), 
                    args.get_newDate().getMonth(), 
                    args.get_newDate().getYear());             
                 
                radTextBox1.set_value(usWeek); 
                radTextBox2.set_value(eurWeek);                 
            } 
             
 
            </script> 
 
            <telerik:RadDateInput SelectionOnFocus="SelectAll" Width="400px" EmptyMessage="Enter the Date you wish to calculate" ID="RadDateInput1" runat="server" > 
                <ClientEvents OnValueChanged="ValueChanged" /> 
                <EnabledStyle BorderColor="blue" BorderStyle="Solid" Font-Size="X-Large" /> 
                <EmptyMessageStyle ForeColor="blue" /> 
            </telerik:RadDateInput> 
            <br /> 
            <telerik:RadTextBox Width="300px" EmptyMessage="U.S. Standard:" ReadOnly="true" ID="RadTextBox1" runat="server" Label="U.S. Standard:"
            </telerik:RadTextBox> 
            <br /> 
            <telerik:RadTextBox Width="300px" EmptyMessage="Europe and ISO Standard:" ReadOnly="true" ID="RadTextBox2" runat="server" Label="ISO Standard: "
            </telerik:RadTextBox>             
        </div> 
    </form> 
</body> 
</html> 
 

I hope this helps.


Greetings,
Plamen
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
bEnDi
Top achievements
Rank 2
answered on 26 Sep 2008, 10:33 AM
Hi!!
Yes!  i think you get what i mean what have produce the result i want. One last thing is, could you post the code in VB? I'm using VB for all my coding. Sorry for the inconvienent but i hope you can do that for me.

Thanks for providing such fast response and solution.
0
Sebastian
Telerik team
answered on 26 Sep 2008, 10:38 AM
Hi Lendi,

The code snippets posted by my colleague are in javascript language - or am I missing something obvious? You do not need to convert them as they can be used in C# or VB.NET project directly.

Regards,
Stephen
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
bEnDi
Top achievements
Rank 2
answered on 30 Sep 2008, 06:44 AM
Hi,

I have try the code you provide. I've compiled the code and there's no error appear but the function doesn't work. After i enter the date, the textbox1 and textbox2 doesn't show anything. I'm very new to this, hope i will get help on this. 

<%

@ Page Language="C#" %>

<%

@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>

<!

DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

 

<

html xmlns="http://www.w3.org/1999/xhtml">

<

head id="Head1" runat="server">

<title>Untitled Page</title>

</

head>

<

body>

<form id="form1" runat="server"> &nbsp;<telerik:RadScriptManager ID="RadScriptManager1" runat="server" EnableScriptGlobalization="True"

EnableScriptLocalization="True">

</telerik:RadScriptManager>

<div>

<script type="text/javascript">

// Code to calculate Eur weeknumber

function getWeekEUR(day, month, year)

{

year = y2k(year);

var when = new Date(year,month,day);

var newnewYear = new Date(year,0,1);

var modDay = newYear.getDay();

if (modDay == 0) modDay=6; else modDay--;

var daynum = ((Date.UTC(y2k(year),when.getMonth(),when.getDate(),0,0,0) -

Date.UTC(y2k(year),0,1,0,0,0)) /1000/60/60/24) + 1;

if (modDay < 4 ) {

var weeknum = Math.floor((daynum+modDay-1)/7)+1;

}

else {

var weeknum = Math.floor((daynum+modDay-1)/7);

if (weeknum == 0) {

year--;

var prevNewYear = new Date(year,0,1);

var prevmodDay = prevNewYear.getDay();

if (prevmodDay == 0) prevmodDay = 6; else prevmodDay--;

if (prevmodDay < 4) weeknum = 53; else weeknum = 52;

}

}

return + weeknum;

}

// End Eur weeknumber

// Code to calculate week number

function getWeek(day, month, year)

{

year = y2k(year);

var when = new Date(year,month,day);

var newnewYear = new Date(year,0,1);

var offset = 7 + 1 - newYear.getDay();

if (offset == 8) offset = 1;

var daynum = ((Date.UTC(y2k(year),when.getMonth(),when.getDate(),0,0,0) - Date.UTC(y2k(year),0,1,0,0,0)) /1000/60/60/24) + 1;

var weeknum = Math.floor((daynum-offset+7)/7);

if (weeknum == 0) {

year--;

var prevNewYear = new Date(year,0,1);

var prevOffset = 7 + 1 - prevNewYear.getDay();

if (prevOffset == 2 || prevOffset == 8) weeknum = 53; else weeknum = 52;

}

return weeknum;

}

function y2k(number) { return (number < 1000) ? number + 1900 : number; }

// End code to calculate week number

function ValueChanged(sender, args)

{

var radTextBox1 = $find("<%= RadTextBox1.ClientID %>");

var radTextBox2 = $find("<%= RadTextBox2.ClientID %>");

if (!args.get_newDate())

{

radTextBox1.clear();

radTextBox2.clear();

return;

}

var usWeek = getWeek(

args.get_newDate().getDate(),

args.get_newDate().getMonth(),

args.get_newDate().getYear());

var eurWeek = getWeekEUR(

args.get_newDate().getDate(),

args.get_newDate().getMonth(),

args.get_newDate().getYear());

radTextBox1.set_value(usWeek);

radTextBox2.set_value(eurWeek);

}

</script>

<telerik:RadDateInput SelectionOnFocus="SelectAll" Width="400px" EmptyMessage="Enter the Date you wish to calculate" ID="RadDateInput1" runat="server" OnTextChanged="ValueChanged" >

<ClientEvents OnValueChanged="ValueChanged" />

<EnabledStyle BorderColor="blue" BorderStyle="Solid" Font-Size="X-Large" />

<EmptyMessageStyle ForeColor="blue" />

</telerik:RadDateInput>

<br />

<telerik:RadTextBox Width="300px" EmptyMessage="U.S. Standard:" ReadOnly="true" ID="RadTextBox1" runat="server" Label="U.S. Standard:">

</telerik:RadTextBox>

<br />

<telerik:RadTextBox Width="300px" EmptyMessage="Europe and ISO Standard:" ReadOnly="true" ID="RadTextBox2" runat="server" Label="ISO Standard: ">

</telerik:RadTextBox>

</div>

</form>

</

body>

</

html>

0
Accepted
Missing User
answered on 30 Sep 2008, 08:31 AM
Hello Lendi,


Please find attached a sample web application that demonstrates the needed approach.

Sincerely yours,
Plamen
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
Calendar
Asked by
bEnDi
Top achievements
Rank 2
Answers by
Missing User
bEnDi
Top achievements
Rank 2
Sebastian
Telerik team
Share this question
or