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

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.

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


How do you want it?
Two date objects, a string, an array of dates ...?

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

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 ...?

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

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"));

        }
    }
}

Thanks It worked

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.