Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialDmitri Mikhalev
4,462 PointsHow do I set a DateTime field to a specific date?
I believe that we only practiced ".Now" and ."Today" earlier, or I might just have forgotten about it. Anyways.
Say that I am instantiating a ReleaseDate class instance and I want to set the date to 4the June, 2002.. what should I put to the right side of the equals sign? :
album.ReleaseDate = (2002, 6, 4)????;
The field in question:
public DateTime ReleaseDate { get; set; }
1 Answer
Steven Parker
231,248 PointsLooks like you resolved your own issue, congratulations!
Another way you could do it:
album.ReleaseDate = Convert.ToDateTime("06/04/2002");
Dmitri Mikhalev
4,462 PointsDmitri Mikhalev
4,462 PointsLike this?
album.ReleaseDate = new DateTime(2002, 6, 4);