SitePoint Sponsor |
|
User Tag List
Results 1 to 13 of 13
-
May 3, 2009, 22:48 #1
- Join Date
- Jan 2009
- Posts
- 176
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
how to get today's date in this format?
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
-
May 3, 2009, 23:12 #2
- Join Date
- Feb 2005
- Location
- Clogland
- Posts
- 322
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Something like this?
Code Csharp:String.Format("{0:MM/dd/yyyy HH:mm:ss}", dt);
-
May 3, 2009, 23:27 #3
- Join Date
- Jan 2009
- Posts
- 176
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
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
-
May 3, 2009, 23:48 #4
- Join Date
- Jul 2004
- Location
- Cape Town, South Africa
- Posts
- 2,880
- Mentioned
- 48 Post(s)
- Tagged
- 0 Thread(s)
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
-
May 3, 2009, 23:52 #5
- Join Date
- Jan 2009
- Posts
- 176
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
-
May 4, 2009, 00:07 #6
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")
Hanan Moiseyev
Online games and Videos - http://www.playwithroger.com
Share your art - http://www.iscrawl.com
-
May 4, 2009, 01:12 #7
- Join Date
- Jan 2009
- Posts
- 176
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
-
May 4, 2009, 04:39 #8
- Join Date
- Feb 2005
- Location
- Clogland
- Posts
- 322
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Does this work?
Code Csharp:if (fromDate.Date != DateTime.Now.Date)
you can test with this
Code Csharp:Response.Write(DateTime.Now.Date.ToString());
-
May 4, 2009, 12:44 #9
- Join Date
- Apr 2009
- Location
- South Florida
- Posts
- 187
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
How do you read data to fromDate, how did you define your variable fromDate
-
May 4, 2009, 23:02 #10
- Join Date
- May 2009
- Posts
- 3
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
-
May 5, 2009, 02:26 #11
- Join Date
- Jan 2009
- Posts
- 176
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
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.
-
May 5, 2009, 02:27 #12
- Join Date
- Jan 2009
- Posts
- 176
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
-
May 7, 2009, 23:17 #13
- Join Date
- Jan 2009
- Posts
- 176
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
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
Bookmarks