DateTime.AddSeconds()

Hi

Please can somebody point out what I’m doing wrong here. Tried 2 methods to get this working, but both are failing!

DateTime bookingDateTime = new DateTime(2021, 7, 15, 16, 0, 0);
bookingDateTime.AddMinutes(45);
bookingDateTime.AddSeconds(30);

MessageBox.Show(bookingDateTime.ToString("dd/MM/yyyy HH:MM:ss"));

and

DateTime bookingDateTime = Convert.ToDateTime("2021-07-14");
System.TimeSpan secsPastMidnight = new System.TimeSpan(0, 0, 28800);
bookingDateTime.Add(secsPastMidnight);

MessageBox.Show(bookingDateTime.ToString("dd/MM/yyyy HH:MM:ss"));

Both result in the same thing, 7 mins get added…
image

Thank you for reading!

Use HH:mm:ss

what a donut, MM means month doesn’t it! I just wasn’t seeing it, should have clocked that the 7 meant July.

thanks very much!

1 Like