date problem [modified]
-
string fromdate= "31/08/2009"; string todate = "20/08/2009"; i have to decrase a day for the todate can u plz specify how to decrease the date for one day... string fromdate ="31/08/2009"; string todate = "20/08/2009"; string newdate =(DateTime.Parse(todate ).AddDays(-1)).ToString("dd/MM/yyyy"); but it was showing error
modified on Monday, August 31, 2009 4:23 AM
-
string fromdate= "31/08/2009"; string todate = "20/08/2009"; i have to decrase a day for the todate can u plz specify how to decrease the date for one day... string fromdate ="31/08/2009"; string todate = "20/08/2009"; string newdate =(DateTime.Parse(todate ).AddDays(-1)).ToString("dd/MM/yyyy"); but it was showing error
modified on Monday, August 31, 2009 4:23 AM
-
You do not have semi-colons in the first two statements. Is that a typo or the problem? If that is typo, then post the error message you get.
It's not necessary to be so stupid, either, but people manage it. - Christian Graus, 2009 AD
-
What is the error it is throwing then?
It's not necessary to be so stupid, either, but people manage it. - Christian Graus, 2009 AD
-
string fromdate= "31/08/2009"; string todate = "20/08/2009"; i have to decrase a day for the todate can u plz specify how to decrease the date for one day... string fromdate ="31/08/2009"; string todate = "20/08/2009"; string newdate =(DateTime.Parse(todate ).AddDays(-1)).ToString("dd/MM/yyyy"); but it was showing error
modified on Monday, August 31, 2009 4:23 AM
Actually the problem is DateTime parses according to the CultureSettings applied on the computer. If your global Date format is MM/dd/yyyy you cannot parse in dd/MM/yyyy. You can specify format while parse, using
ParseExact
function rather thanParse
. :thumbsup:Abhishek Sur
My Latest Articles **Create CLR objects in SQL Server 2005 C# Uncommon Keywords Read/Write Excel using OleDB
**Don't forget to click "Good Answer" if you like to.
-
Actually the problem is DateTime parses according to the CultureSettings applied on the computer. If your global Date format is MM/dd/yyyy you cannot parse in dd/MM/yyyy. You can specify format while parse, using
ParseExact
function rather thanParse
. :thumbsup:Abhishek Sur
My Latest Articles **Create CLR objects in SQL Server 2005 C# Uncommon Keywords Read/Write Excel using OleDB
**Don't forget to click "Good Answer" if you like to.
-
string fromdate= "31/08/2009"; string todate = "20/08/2009"; i have to decrase a day for the todate can u plz specify how to decrease the date for one day... string fromdate ="31/08/2009"; string todate = "20/08/2009"; string newdate =(DateTime.Parse(todate ).AddDays(-1)).ToString("dd/MM/yyyy"); but it was showing error
modified on Monday, August 31, 2009 4:23 AM
-
try this code to decrease the date Label1.Text = DateTime.Now.AddDays(-1).ToString(); after u Get date time u can change as per your Requirement
modified on Monday, August 31, 2009 5:32 AM
-
use this
DateTime dt = DateTime.ParseExact("18/02/2001", "dd/MM/yyyy", new CultureInfo("en-US"));
You will get what you want. :cool:
Abhishek Sur
My Latest Articles **Create CLR objects in SQL Server 2005 C# Uncommon Keywords Read/Write Excel using OleDB
**Don't forget to click "Good Answer" if you like to.
-
iam not asking for lable ... iam getting a date in string format i want to decrease the particular date which is in string format
Convert the string format date into Datetime format i.e. use the following code
DateTime dt = DateTime.ParseExact("25/11/2009", "dd/MM/yyyy", new CultureInfo("en-US"));
or u Can Use This
string ssd = DateTime.Now.AddDays(-1).ToString();
DateTime asd = Convert.ToDateTime(ssd);
ssd = asd.AddDays(-1).ToString();if this is not Your Answer I am Sorry..!
modified on Monday, August 31, 2009 6:07 AM
-
string fromdate= "31/08/2009"; string todate = "20/08/2009"; i have to decrase a day for the todate can u plz specify how to decrease the date for one day... string fromdate ="31/08/2009"; string todate = "20/08/2009"; string newdate =(DateTime.Parse(todate ).AddDays(-1)).ToString("dd/MM/yyyy"); but it was showing error
modified on Monday, August 31, 2009 4:23 AM
you can do by this, just remove the opening and closing brace. string newdate =DateTime.Parse(todate).AddDays(-1).ToString("dd/MM/yyyy");
-
string fromdate= "31/08/2009"; string todate = "20/08/2009"; i have to decrase a day for the todate can u plz specify how to decrease the date for one day... string fromdate ="31/08/2009"; string todate = "20/08/2009"; string newdate =(DateTime.Parse(todate ).AddDays(-1)).ToString("dd/MM/yyyy"); but it was showing error
modified on Monday, August 31, 2009 4:23 AM
-
Hi , First parse string into date format and remember u should use yyyy/mm/dd format. datetime date = datetime.parse(date); date = date .AddDays(-1) Thanks, Amit Patel
just get month year day through substring string year = txtdate.Text.Substring(6, 4); string month = txtdate.Text.Substring(3, 2); string day = txtdate.Text.Substring(0, 2); DateTime dt=DateTime.Parse(year+"/"+month+"/"+day); string date = dt .AddDays(-1);
-
string fromdate= "31/08/2009"; string todate = "20/08/2009"; i have to decrase a day for the todate can u plz specify how to decrease the date for one day... string fromdate ="31/08/2009"; string todate = "20/08/2009"; string newdate =(DateTime.Parse(todate ).AddDays(-1)).ToString("dd/MM/yyyy"); but it was showing error
modified on Monday, August 31, 2009 4:23 AM
string year = txtdate.Text.Substring(6, 4); string month = txtdate.Text.Substring(3, 2); string day = txtdate.Text.Substring(0, 2); DateTime dt=DateTime.Parse(year+"/"+month+"/"+day); date = date .AddDays(-1) txtdate is the textbox for date input:rose: