Click here to Skip to main content
15,891,837 members
Home / Discussions / C#
   

C#

 
QuestionDATE HELP Pin
5fingers7-Sep-09 2:02
5fingers7-Sep-09 2:02 
AnswerRe: DATE HELP Pin
DaveyM697-Sep-09 2:07
professionalDaveyM697-Sep-09 2:07 
GeneralRe: DATE HELP Pin
5fingers7-Sep-09 2:24
5fingers7-Sep-09 2:24 
GeneralRe: DATE HELP Pin
stancrm7-Sep-09 2:32
stancrm7-Sep-09 2:32 
GeneralRe: DATE HELP Pin
5fingers7-Sep-09 2:45
5fingers7-Sep-09 2:45 
GeneralRe: DATE HELP Pin
Richard MacCutchan7-Sep-09 2:48
mveRichard MacCutchan7-Sep-09 2:48 
GeneralRe: DATE HELP Pin
5fingers7-Sep-09 2:58
5fingers7-Sep-09 2:58 
GeneralRe: DATE HELP [modified] Pin
DaveyM697-Sep-09 3:04
professionalDaveyM697-Sep-09 3:04 
That can't be done. The struct is DateTime not Date. You can either ignore the time part altogether (be careful in any DateTime comparisons - Use the Date property of the DateTime to retrieve the DateTime with the default time e.g. DateTime.Now.Date) or create your own class/struct to just hold the date and create implicit/explicit operator overloads to/from DateTime.

[Edit} A little code to help you get started and to show how easy it is to create a wrapper to DateTime [/Edit]

/// <summary>
/// Wrapper around System.DateTime to work with only the Date part.
/// </summary>
public struct Date
{
    public static readonly Date MaxValue = new Date(DateTime.MaxValue);
    public static readonly Date MinValue = new Date(DateTime.MinValue);

    private DateTime _DateTime;

    public Date(DateTime dateTime)
    {
        _DateTime = dateTime.Date;
    }

    public static implicit operator DateTime(Date date)
    {
        return date._DateTime;
    }
    public static explicit operator Date(DateTime dateTime)
    {
        return new Date(dateTime);
    }

    public static Date Now
    {
        get { return new Date(DateTime.Now); }
    }

    public override string ToString()
    {
        return _DateTime.ToString("d");
    }
    public string ToString(IFormatProvider provider)
    {
        return _DateTime.ToString(provider);
    }
    public string ToString(string format)
    {
        return _DateTime.ToString(format);
    }
    public string ToString(string format, IFormatProvider provider)
    {
        return _DateTime.ToString(format, provider);
    }
}


Dave

Generic BackgroundWorker - My latest article!
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
Why are you using VB6? Do you hate yourself? (Christian Graus)

modified on Monday, September 7, 2009 9:29 AM

GeneralRe: DATE HELP Pin
5fingers7-Sep-09 3:41
5fingers7-Sep-09 3:41 
GeneralRe: DATE HELP Pin
Christian Graus7-Sep-09 11:43
protectorChristian Graus7-Sep-09 11:43 
GeneralRe: DATE HELP Pin
Henry Minute7-Sep-09 3:41
Henry Minute7-Sep-09 3:41 
AnswerRe: DATE HELP Pin
Arun Jacob7-Sep-09 2:07
Arun Jacob7-Sep-09 2:07 
AnswerRe: DATE HELP Pin
stancrm7-Sep-09 2:10
stancrm7-Sep-09 2:10 
GeneralRe: DATE HELP Pin
itsravie7-Sep-09 3:47
itsravie7-Sep-09 3:47 
Questionshowing multiple rows in a table after an SQL query Pin
Emmet_Brown7-Sep-09 1:41
Emmet_Brown7-Sep-09 1:41 
AnswerRe: showing multiple rows in a table after an SQL query Pin
SeMartens7-Sep-09 2:02
SeMartens7-Sep-09 2:02 
GeneralRe: showing multiple rows in a table after an SQL query Pin
Emmet_Brown7-Sep-09 2:06
Emmet_Brown7-Sep-09 2:06 
GeneralRe: showing multiple rows in a table after an SQL query Pin
SeMartens7-Sep-09 2:15
SeMartens7-Sep-09 2:15 
GeneralRe: showing multiple rows in a table after an SQL query Pin
Emmet_Brown7-Sep-09 2:39
Emmet_Brown7-Sep-09 2:39 
QuestionPlz help Pin
itsravie7-Sep-09 1:38
itsravie7-Sep-09 1:38 
AnswerRe: Plz help Pin
J4amieC7-Sep-09 1:40
J4amieC7-Sep-09 1:40 
GeneralRe: Plz help Pin
Tom Deketelaere7-Sep-09 2:08
professionalTom Deketelaere7-Sep-09 2:08 
GeneralRe: Plz help Pin
J4amieC7-Sep-09 2:37
J4amieC7-Sep-09 2:37 
AnswerRe: Plz help Pin
stancrm7-Sep-09 1:46
stancrm7-Sep-09 1:46 
GeneralRe: Plz help Pin
itsravie7-Sep-09 1:50
itsravie7-Sep-09 1:50 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.