SitePoint Sponsor

User Tag List

Results 1 to 13 of 13

Hybrid View

  1. #1
    SitePoint Zealot
    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

  2. #2
    SitePoint Addict
    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);

  3. #3
    SitePoint Zealot
    Join Date
    Jan 2009
    Posts
    176
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by SlitheryImp View Post
    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

  4. #4
    SitePoint Mentor NightStalker-DNS's Avatar
    Join Date
    Jul 2004
    Location
    Cape Town, South Africa
    Posts
    2,868
    Mentioned
    37 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

  5. #5
    SitePoint Zealot
    Join Date
    Jan 2009
    Posts
    176
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by NightStalker-DNS View Post
    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
    that's true..
    but i dont want time.
    i only want today's date n time i want in 00:00:00 format.
    how to do this?

  6. #6
    SitePoint Zealot iScrawl's Avatar
    Join Date
    Mar 2009
    Posts
    112
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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

  7. #7
    SitePoint Zealot
    Join Date
    Jan 2009
    Posts
    176
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by iScrawl View Post
    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")
    if (fromDate != DateTime.Now())
    so now wt to write in place of DateTime.Now?
    please tell me clearly.

  8. #8
    SitePoint Addict
    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());

  9. #9
    SitePoint Zealot
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •