How to show Birthday reminder in asp.net c# for next 7 days

In this article, many times we need to show to birthday reminder on label.  In this below code if we will show birthday of next 7 days (a week).

Source Code:-

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="birthday.aspx.cs" Inherits="birthday" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>

</head>
<body>
    <form id="form1" runat="server">
    <div>
   
        <asp:Label ID="lbbirthday" runat="server"></asp:Label>
   
    </div>
    </form>
</body>
</html>


Code(c#):-
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class birthday : System.Web.UI.Page


{
    protected void Page_Load(object sender, EventArgs e)
    {
        DateTime birthday = Convert.ToDateTime("1991/12/24");
        int years = DateTime.Now.Year - birthday.Year;
        birthday = birthday.AddYears(years);
        DateTime check = DateTime.Now.AddDays(7);
        if ((birthday > DateTime.Now) && (birthday < check))
        {
            lbbirthday.Text = ("This week is your birthday !!!");
        }
        else
        {
            lbbirthday.Text = ("This week no birthday");       
        }
    }
}


Out Put:-


How to show Birthday reminder in asp.net c# for next 7 days How to show Birthday reminder in asp.net c# for next 7 days Reviewed by NEERAJ SRIVASTAVA on 8:29:00 PM Rating: 5

1 comment:

Powered by Blogger.