DateTime

  • Thread starter Thread starter Gigs_
  • Start date Start date
G

Gigs_

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", "(e-mail address removed)", "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?
 
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", "(e-mail address removed)", "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", "(e-mail address removed)",
DateTime.Parse("12/12/2981"));

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

Hans Kesting
 
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.
 
Gigs_ said:
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("Person isn't born yet!");
this.fname = fn;
this.lname = ln;
this.email = email;
this.dob = dob;
}

Christof
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top