0

Hi Everybody

I am trying to get some function which returns

- current month name
- current year
- date range ( for February displaying 2/1/2007 - 2/28/2007)
-year range ( 1 Jan 2007 - 31 Dec 2007)

I was wondering, is there any functions for these?
I searched a lot, but couldnt find a solution

It will be really greatful if someone can help me in this.

Thanks

2
Contributors
8
Replies
12
Views
10 Years
Discussion Span
Last Post by Sarah Lee
0

The DateTime object has properties for month, day, year, etc. DateTime.Now is today's date. You can go from there.
Note that ToString is overloaded for DateTime in order to format a date for output.

0

I got it worked.
To get current month name in VB.net
Today.ToString("MMMM")
To get current year
Format(Now, "yyyy")

if someone knows how to get
date range ( for February displaying 2/1/2007 - 2/28/2007)
-year range ( 1 Jan 2007 - 31 Dec 2007)

please help me
Thanks


0

I want to display as

2/1/2007 - 2/28/2007 --- 2 dates
1 Jan 2007 - 31 Dec 2007 -- strings

I dont know whether it is possible or not?
Or am I thinking to do which is not possible?

thanks

0

Sure it's possible.
Where does the range come from? That is, the start and end dates of the current month and current year, or user input, or ...?

0

Yes, it is the startDate and endDate of current month and current year
It is not of user input
When the user clciks a button, i want to set a label's text as the
- start and end date of current month OR
-start and end date of current year

depends on the button click

0

Sure. A simple console app to demonstrate.

using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            DateTime fromDate = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1);
            Console.WriteLine(fromDate.ToString("M/d/yyyy"));

            DateTime toDate = new DateTime(DateTime.Now.Year, DateTime.Now.AddMonths(1).Month, 1);
            toDate = toDate.AddDays(-1);
            Console.WriteLine(toDate.ToString("M/d/yyyy"));

            fromDate = new DateTime(DateTime.Now.Year, 1, 1);
            Console.WriteLine(fromDate.ToString("d MMM yyyy"));
            toDate = new DateTime(DateTime.Now.AddYears(1).Year, 1, 1);
            toDate = toDate.AddDays(-1);
            Console.WriteLine(toDate.ToString("d MMM yyyy"));

        }
    }
}
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.