c# - Get yesterday's date from the date entered -
c# - Get yesterday's date from the date entered -
i have console application accepts date parameter. however, date passed string in format:
string dt = datetime.now.tostring("yyyymmdd");
once date entered need programmatically day - 1
entered date. since string, cannot calculation.
for example, user enters:
20141023
i need subtract day date get:
20141022
i did quick prepare solve immediate need, however, not right way , has bug:
int yt = int32.parse(dt) - 1;
and turn around , convert yt.tostring()
the above solution not work if it's 1st
of month.
is there way can programmatically yesterday's date in format (yyyymmdd)
without changing format , perchance not using timespan
?
try this...
datetime info = datetime.parseexact("20141023", "yyyymmdd", cultureinfo.invariantculture); console.writeline("{0} - {1}", data, data.adddays(-1).tostring("yyyymmdd"));
c# date console-application
Comments
Post a Comment