GRChandrashekar
asked on
Datatable
Following function returns datatable containing two strings firstdayoflastmonth, lastdayoflastmonth
public static DataTable returnfirstlastdateofprevi ousmonth()
{
var Viewpreviousmonthfirstlast date = new VPreviousmonthfirstlastdat eTypedView ();
var adapterpreviousmonthfirstl astdate = new DataAccessAdapter();
adapterpreviousmonthfirstl astdate.Fe tchTypedVi ew(Viewpre viousmonth firstlastd ate.GetFie ldsInfo(), Viewpreviousmonthfirstlast date);
var DataTablepreviousmonthfirs tlastdate = new DataTable();
DataTablepreviousmonthfirs tlastdate. Clear();
DataTablepreviousmonthfirs tlastdate = Viewpreviousmonthfirstlast date;
return DataTablepreviousmonthfirs tlastdate;
}
I need to modify this function to return 2 outputs in date format without time for fields firstdayoflastmonth, lastdayoflastmonth
public static DataTable returnfirstlastdateofprevi
{
var Viewpreviousmonthfirstlast
var adapterpreviousmonthfirstl
adapterpreviousmonthfirstl
var DataTablepreviousmonthfirs
DataTablepreviousmonthfirs
DataTablepreviousmonthfirs
return DataTablepreviousmonthfirs
}
I need to modify this function to return 2 outputs in date format without time for fields firstdayoflastmonth, lastdayoflastmonth
ASKER
since it is data table i need to convert to date format and not int.
I have given a sample only and you can return data table in the parameter.
Use Convert.ToDateTime(..) to convert string into date format
ASKER
This line
processmonthend.Monthendda te =
Convert.ToDateTime(DBLastD ateOfLastM onth.Rows[ 0]["LASTDA YOFLASTMON TH"]);
returns date and time. How do I format this to get only date ?
processmonthend.Monthendda
Convert.ToDateTime(DBLastD
returns date and time. How do I format this to get only date ?
to get only date use the following format: MM/dd/yyyy
processmonthend.Monthendda te =
DateTime.Parse(Convert.ToD ateTime(DB LastDateOf LastMonth. Rows[0]["L ASTDAYOFLA STMONTH"]) .ToString( "MM/dd/yyy y"));
processmonthend.Monthendda
DateTime.Parse(Convert.ToD
You can get using tostring as below:
processmonthend.Monthendda te.ToStrin g("dd/MM/y yyy")
processmonthend.Monthendda
if you want the function to return 2 outputs, instead of return datatable you can apply the following:
public static void returnfirstlastdateofpreviousmonth(out DateTime firstdayoflastmonth, out DateTime lastdayoflastmonth)
{
firstdayoflastmonth= DateTime.Parse(Convert.ToDateTime(DBLastDateOfLastMonth.Rows[0]["FIRSTDAYOFLASTMONTH"]).ToString("MM/dd/yyyy"));
lastdayoflastmonth = DateTime.Parse(Convert.ToDateTime(DBLastDateOfLastMonth.Rows[0]["LASTDAYOFLASTMONTH"]).ToString("MM/dd/yyyy"));
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
@starlite551
>>Perhaps this would work better
it ain't better, it simply different way of achieving the same result.
>>Perhaps this would work better
it ain't better, it simply different way of achieving the same result.
I think ToShortDateString() is better than hard-coded format such as ToString("MM/dd/yyyy")
It's simply because ToShortDateString() uses the current culture of the running application and thus will output the better result.
i.e. on fr-FR culture, it will format as dd/MM/yyyy and on en-US, it will show MM/dd/yyyy
It's simply because ToShortDateString() uses the current culture of the running application and thus will output the better result.
i.e. on fr-FR culture, it will format as dd/MM/yyyy and on en-US, it will show MM/dd/yyyy
it depends in the requirements, if the value is stored in DB should be in specific format than hard-coded format is the way to go.
eg.
public static DataTable returnfirstlastdateofprevi
{
....
firstdayoflastmonth = ..
lastdayoflastmonth = ..
....
}