m using asp.net with c# and oracle database.
i want today's date in this format mm/dd/yyyy 00:00:00
like 05/04/2009 00:00:00
hours:min:sec i want in this way 00:00:00 to check condition.
i want exactly in this way...wt to write for this?
please help
Printable View
m using asp.net with c# and oracle database.
i want today's date in this format mm/dd/yyyy 00:00:00
like 05/04/2009 00:00:00
hours:min:sec i want in this way 00:00:00 to check condition.
i want exactly in this way...wt to write for this?
please help
Something like this?
Code Csharp:String.Format("{0:MM/dd/yyyy HH:mm:ss}", dt);
it's not working..
if (fromDate != DateTime.Now.ToString("dd-MM-yy"))
write now m doing this but not getting output as i want.
let me explain in detail.
m getting todays date like 05/04/2009 00:00:00 in fromDate variable.
now i want to check condition if fromDate is same as 05/04/2009 00:00:00.
i want today'date with hh:min:sec as 00:00:00
That is converting it to a string. and your trying to compare date to string which is not going to work. You should just be able to compare 2 dates to each other.
eg. if (fromDate <= DateTime.Now)
or (fromDate == DateTime.Now);
But DateTime.Now will have the current time as well, so keep that in mind wen comparing the 2
There is probably a pre-build function for that in .NET, in VB it was dateformat...
I can also suggest the simple way:
Code:cdate(day(now) & "/" & month(now) & "/" & year(now) & " 00:00:00")
Does this work?
Code Csharp:if (fromDate.Date != DateTime.Now.Date)
you can test with this
Code Csharp:Response.Write(DateTime.Now.Date.ToString());
How do you read data to fromDate, how did you define your variable fromDate
string fromDate = dtFromDate.fullDate;
//dtfromDate is usercontrol provided by the company..so i cant make any changes on this.
in fromDate m getting by default todays date n hh:mm:sec as 00:00:00
so i want to check condition if today's date like mm/dd/yyyy 00:00:00 is same or not.
so i need only today's date n not time..
i want exactly in this format mm/dd/yyyy 00:00:00
i want only date n hh:mm:sec as 00:00:00.
hello friends,
i got the solution by writing this code..actually i ws dong mistake in taking the format.
earlier i was not using mm in a Capital letter..
string date = string.Empty;
DateTime tDate = DateTime.Now.Date;
date = tDate.ToString("MM/dd/yyyy");
date = date + " 00:00:00";
output
05/08/2009 00:00:00