umadik
umadik

Reputation: 111

How Can I Set Day Of DateTime in Vb?

I have a DateTime variable like that:

Dim tarih2 As New DateTime( _
    year(tarih3), _
    month(tarih3), _
    DateTime.DaysInMonth(year(tarih3), month(tarih3)))

and I need to set the day part to a specific value. How can I set day of a DateTime?

Upvotes: 0

Views: 2429

Answers (2)

Geoff
Geoff

Reputation: 8878

DateTime is immutable, so you can't change the value; you can only construct a new instance by either calling AddDays() for a relative offset, or by using the constructor in a similar manner to that in your question:

tarih2 = new DateTime(year(tarih2), month(tarih2), newDayValue)

Upvotes: 5

Ric
Ric

Reputation: 13258

Use DateTime.AddDays Method

tarih2.AddDays(1) ' adds one day to an instance of DateTime tarih2

Upvotes: 0

Related Questions