Asp.net Aydaki Gün Sayısını Öğrenme
Asp.net ile sistem tarihine göre o ay ki gün sayısını öğrenebiliriz bunun için DateTime.DaysInMonth fonksiyonunu kullanacağız bu fonksiyon ile kendisine verilen ay ve yıl değerlerine göre o ay ki gün sonucunu öğrenebiliyoruz.
<%@ Page Language="C#" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <script runat="server"> protected void Page_Load(object sender, System.EventArgs e) { if(!this.IsPostBack) { Button1.Font.Bold = true; Button1.ForeColor = System.Drawing.Color.IndianRed; Button1.Text = "Bu Ay Kaç Gün"; Label1.Font.Size = FontUnit.Larger; Label1.ForeColor = System.Drawing.Color.IndianRed; Label1.Font.Bold = true; Label1.Font.Italic = true; } } protected void Button1_Click(object sender, System.EventArgs e) { int yil = DateTime.Now.Year; int ay = DateTime.Now.Month; string kacgun = DateTime.DaysInMonth(yil,ay).ToString(); Label1.Text = "Bugün " + DateTime.Now.ToLongDateString(); Label1.Text += "<br />Bu Ay: " + kacgun+" Gün"; } </script> <html xmlns="http://www.w3.org/1999/xhtml"> <head id="Head1" runat="server"> <title>asp.net date time örnekleri: Aydaki Gün Sayısını Öğrenme "DaysInMonth" </title> </head> <body> <form id="form1" runat="server"> <div> <h2 style="color:Teal">asp.net date time örnekleri: <br />Aydaki Gün Sayısını Öğrenme "DaysInMonth"</h2> <asp:Label ID="Label1" runat="server" > </asp:Label> <br /><br /> <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" /> </div> </form> </body> </html>