CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Oct 2004
    Posts
    65

    Thumbs up How to get only date value in C#

    How to get only date value in C#.

    i am using system.datetime.now.date
    it returns date with time.

    Can any one give the solution


    Regards,
    sivakumar

  2. #2
    Join Date
    Apr 2005
    Posts
    576

    Re: How to get only date value in C#

    There is no date type in .Net, only DateTime.

    To get only date you can do one of the following:

    Code:
    // Get current date and time
    DateTime dt=DateTime.Now;
    
    // Get year, month, and day
    int year=dt.Year;
    int month=dt.Month;
    int day=dt.Day;
    
    // Get datetime at midnight
    DateTime date=dt.Date;
    
    // Get long date string
    string longDate=dt.ToLongDateString();
    
    // Get short date string
    string shortDate=dt.ToShortDateString();
    
    // Get Ole Automation Date (number of days from midnight, 30 December 1899)
    double oaDate=dt.ToOADate();
    Last edited by klintan; August 18th, 2005 at 03:06 AM.

  3. #3
    Join Date
    Oct 2004
    Posts
    65

    Question Re: How to get only date value in C#

    using ultradatetimeeditor.value i am storing it in database and its value in database is 2005-08-18 00:00:00.000
    and when i try to use
    DateTime.Now.Date.ToShortDateString() its not retreive the record.

    How come will i get the record by passing exact value as in database

    Pls. give information.

    Regards,
    Sivakumar.kr

  4. #4
    Join Date
    Aug 2006
    Posts
    1

    Re: How to get only date value in C#

    try this way.


    txtDueDate.MaskInput = "{LOC}mm/dd/yyyy";

  5. #5
    Join Date
    Dec 2003
    Location
    http://map.search.ch/zuerich.en.html
    Posts
    1,074

    Re: How to get only date value in C#

    If your DB column type is "DATE" it should work.

    If your column type is TIMESTAMP you may have to make your query a range. eg. WHERE col >= today AND col < tomorrow
    Useful? Then click on (Rate This Post) at the top of this post.

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured