How to get first date of the month ?

Posted by Laghaterohan under Regular Expressions on 2/19/2011 | Points: 10 | Views : 5909 | Status : [Member] | Replies : 3
Hello,

I want to display First date of the month (dd/mm/yyyy) format according to the date provided by the user . I WANT TO FULLFILL THIS REQUIREMENT WHILE
DISPLAYING THE DATA IN CRYSTAL REPORT.

ex. if the user submits the date as 19/02/2011 i should be able to display
PERIOD FROM : 1/02/2011 to 19/02/2011 OR
1/02/2011 to 28/02/2011 (Last date of the month submitted by the user)


To simplify futher, the date will be passed from front end by the user...however while displaying the report i should be able to display date within the period as mentioned above.

Please help...its an urgent requirement of my client :(


THANKS!

Best Regards,
Rohan Laghate



Responses

Posted by: Karthikanbarasan on: 2/19/2011 [Member] [Moderator] [Microsoft_MVP] [MVP] Silver | Points: 25

Up
0
Down
Hi,

Check this link

http://classicasp.aspfaq.com/date-time-routines-manipulation/how-do-i-calculate-dates-such-as-the-first-day-of-the-month.html

Thanks
Karthik
www.f5Debug.net

Laghaterohan, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Madhu.b.rokkam on: 2/19/2011 [Member] [MVP] Bronze | Points: 25

Up
0
Down
in the frontend side write a c# function

private void GetDates(DateTime givenDate, out DateTime firstDate, out DateTime lastDate)
{
int date = givenDate.Day;
int mon = givenDate.Month;
int year = givenDate.Year;
int noOfdays = DateTime.DaysInMonth(year, mon);

firstDate = new DateTime(year, mon, 1);
lastDate = new DateTime(year, mon, noOfdays);
}

and you can get that as

DateTime firstDate, lastdate, givendate;
givendate = Convert.ToDateTime(textBox3.Text);
GetDates(givendate, out firstDate, out lastdate);
textBox1.Text = firstDate.ToShortDateString();
textBox2.Text = lastdate.ToShortDateString();

Thanks and Regards
Madhu

Laghaterohan, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Tripati.patro on: 2/19/2011 [Member] Starter | Points: 25

Up
0
Down
Hi,

Try this code..
//Where inputDate is the value provided by user.

var monthStart = new DateTime(inputDate.Year, inputDate.Month, 1);
var monthEnd = monthStart.AddMonths(1).AddDays(-1);


B.Tripati Patro
Oracle Certified Associate

Laghaterohan, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response