Posts

Showing posts with the label date

How to get month days count from date or month and year

Hi all . Window form application need some calculation of date and days,so require no of days in current month or any date of month. So for that we use on c# in build function to get days count. System.DateTime.DaysInMonth(Year(int), Month(int)); This function output number of days in integer. And we need to input year and month number in integer value. If you have date then we get month and year from it. DateTime NowDate = new DateTime(); int iMonth=NowDate.Month; int iYear=NowDate.Year; If you have month name so need to get number of month int iMonth=DateTime.ParseExact("MonthName", "MMMM", CultureInfo.InvariantCulture).Month For this code need to include using System.Globalization; library. Thanks to read this post. comment if any problem in code.

Insert date in database by DateTimePicker

Hi to all. If you are new in developing so you have mostly problem to add date in database. so i make code for new beginners. first take one  DateTimePicker name it to Dtdate. Set property Format=Short so we get simple date not in long format. Take one button so on click event we save in database. In Button click event. string Dtdate = Dtdate.Value.ToString("yyyy-MM-dd"); Now the string contain date string in "yyyy-MM-dd" format. on save time make query for date. string sQuary="Insert into testTable (Dtdate) Values (#"+Dtdate +"#)" ; Execute this query. In query I use "#" on start and end. that specify this is date. in database date save always in  "yyyy-MM-dd" format so i convert in this format. Thanks for read this post