DateTime

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Gigs_

    #1

    DateTime

    if i us this constructor

    public Person(string fn, string ln, string email, DateTime dob)
    {
    this.fname = fn;
    this.lname = ln;
    this.email = email;
    this.dob = dob; //DateTime.Parse( dob);

    }


    how can i create new person?
    Person p = new Person("john", "doe", "jdoe@oo.co m", "12/12/2981"); this doesnt
    work because it needs datetime object not string. Is there any way to put
    datetime object or i just need to go with string?
  • Hans Kesting

    #2
    Re: DateTime

    Gigs_ was thinking very hard :
    if i us this constructor
    >
    public Person(string fn, string ln, string email, DateTime dob)
    {
    this.fname = fn;
    this.lname = ln;
    this.email = email;
    this.dob = dob; //DateTime.Parse( dob);
    >
    }
    >
    >
    how can i create new person?
    Person p = new Person("john", "doe", "jdoe@oo.co m", "12/12/2981"); this
    doesnt work because it needs datetime object not string. Is there any way to
    put datetime object or i just need to go with string?
    Either use this constructor with
    Person p = new Person("john", "doe", "jdoe@oo.co m",
    DateTime.Parse( "12/12/2981"));

    or add an extra constructor that uses a date-string and does the
    parsing internally.

    Hans Kesting


    Comment

    • Gigs_

      #3
      Re: DateTime

      what i need is when creating person to check is that person put right date. to
      see if today date is after persons birthday date. i tried with datetime.parse,
      but if i put method for checking date in constructor my date string is not jet
      converted to datetime object.

      so when creating persons i need to trow an exception if birthday date of
      particular person is in future.

      Comment

      • Christof Nordiek

        #4
        Re: DateTime

        "Gigs_" <gigs@hi.t-com.hrschrieb im Newsbeitrag
        news:fjr3s6$pl9 $1@ss408.t-com.hr...
        what i need is when creating person to check is that person put right
        date. to see if today date is after persons birthday date. i tried with
        datetime.parse, but if i put method for checking date in constructor my
        date string is not jet converted to datetime object.
        >
        so when creating persons i need to trow an exception if birthday date of
        particular person is in future.
        If you want to check if a DateTime value is in the future, compare it with
        DateTime.Now. (The latter contains only the corrent date.)

        public Person(string fn, string ln, string email, DateTime dob)
        {
        if (dob DateTime.Now)
        throw new Exception("Pers on isn't born yet!");
        this.fname = fn;
        this.lname = ln;
        this.email = email;
        this.dob = dob;
        }

        Christof

        Comment

        Working...