how we display monthinto a variable

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jyoti pandey
    New Member
    • Jun 2007
    • 13

    #1

    how we display monthinto a variable

    sir can we declare variable; in which i want to display only month , like
    if i declare
    datetime dt=datetime.now ;

    then it display todays date and month but i want To display only month.
    sir i am working on asp.net version .5,web developer Express adition
  • shweta123
    Recognized Expert Contributor
    • Nov 2006
    • 692

    #2
    Hi,
    You can get the month like this:

    Dim mon as integer
    mon= month(Datetime. today)



    Originally posted by jyoti pandey
    sir can we declare variable; in which i want to display only month , like
    if i declare
    datetime dt=datetime.now ;

    then it display todays date and month but i want To display only month.
    sir i am working on asp.net version .5,web developer Express adition

    Comment

    • dip_developer
      Recognized Expert Contributor
      • Aug 2006
      • 648

      #3
      Originally posted by jyoti pandey
      sir can we declare variable; in which i want to display only month , like
      if i declare
      datetime dt=datetime.now ;

      then it display todays date and month but i want To display only month.
      sir i am working on asp.net version .5,web developer Express adition
      Have u tried DateTime.Now.Mo nth ??? it will return Month number....
      i.e. if it is January it will return 1....So store month in an Integer variable....... .

      Hope it will help....

      Comment

      • jyoti pandey
        New Member
        • Jun 2007
        • 13

        #4
        Originally posted by dip_developer
        Have u tried DateTime.Now.Mo nth ??? it will return Month number....
        i.e. if it is January it will return 1....So store month in an Integer variable....... .

        Hope it will help....
        sir i declare it datetime type
        and by your method its give error like that

        Cannot implicitly convert type 'int' to 'System.DateTim e'
        sir i am working in asp.net express edition
        i send you my quiry

        DateTime dt = DateTime.Now;
        dt = dt.AddMonths(1) ;
        if (dt.Day.ToStrin g().ToUpper() == "SUNDAY")
        {
        dt.AddDays(1);
        }
        B2.SelectedDate = dt;
        there b2 is a datetimepicker2
        in this when i declare
        datetime dt=datetime.now ;
        it will return date but i want it return only month
        sir pls help me queckly
        sir if U want U can send me salution in my mail
        pandeyjyoti1084 @gmail.com
        thanks

        Comment

        • jyoti pandey
          New Member
          • Jun 2007
          • 13

          #5
          Originally posted by shweta123
          Hi,
          You can get the month like this:

          Dim mon as integer
          mon= month(Datetime. today)
          sir i am working in asp.net express edition in c#
          give me coding of c#

          Comment

          • dip_developer
            Recognized Expert Contributor
            • Aug 2006
            • 648

            #6
            Originally posted by jyoti pandey
            sir i am working in asp.net express edition in c#
            give me coding of c#

            why are u taking DateTime datatype....
            What do u actually want....???

            int mon;
            mon=DateTime.No w.Month;

            Comment

            • dip_developer
              Recognized Expert Contributor
              • Aug 2006
              • 648

              #7
              Originally posted by jyoti pandey
              sir i am working in asp.net express edition in c#
              give me coding of c#

              why are u taking DateTime datatype....
              What do u actually want....???

              tried this???
              int mon;
              mon=DateTime.No w.Month;

              Comment

              • jyoti pandey
                New Member
                • Jun 2007
                • 13

                #8
                Originally posted by dip_developer
                why are u taking DateTime datatype....
                What do u actually want....???

                int mon;
                mon=DateTime.No w.Month;
                because i want to add i month in present month or want to increment in present menth like

                mon = mon.AddMonths(1 );

                and if we taking int then there is no function of addmonths
                give me salution please

                Comment

                • jyoti pandey
                  New Member
                  • Jun 2007
                  • 13

                  #9
                  Originally posted by dip_developer
                  why are u taking DateTime datatype....
                  What do u actually want....???

                  tried this???
                  int mon;
                  mon=DateTime.No w.Month;
                  because i want to add month
                  like

                  mon = mon.AddMonths(1 );

                  increment of menth.
                  ok sir give me result soon

                  Comment

                  • Plater
                    Recognized Expert Expert
                    • Apr 2007
                    • 7872

                    #10
                    I think you are missing something VERY simple here.
                    You have a DateTime object called mon that you want to increment a month to it? AddMonth(1); is perfectly valid

                    Code:
                    DateTime mydt=DateTime.Now;
                    int NumMonths=mydt.Month;
                    //now I have a DateTime object with the current date
                    //and an int with the month number (1 for january, 2 for february, etc)
                    
                    //and if you wanted to, you could do this:
                    mydt.AddMonth(NumMonths);

                    Now it is still not clear what you wish to accomplish but DateTime objects can be added and subtracted from each other.
                    You can also add/subtract ANY number of months with .AddMonth()
                    These are both valid:
                    Code:
                    DateTime mydt=DateTime.Now;
                    mydt.AddMonth(13);
                    mydt.AddMonth(-3);

                    Comment

                    Working...