Jakob_nesnes
(Jakob D V Andersen)
November 15, 2019, 8:02am
1
i have to compare stuff the hour before my program run, but i need time to be 07:00 and not 7:00
also after noon it needs to be 13:00 and not 1:00.
It always need to be the complete hour, so i’ve made it like this variable
lasthour = Datetime.Now.AddHours(-1).TimeOfDay.Hours.ToString+“:00”
but that gives me 7:00
is there a way to turn that into 07:00, but still keep military time format?
thanks
lakshman
(Ganta lakshman)
November 15, 2019, 8:06am
2
@Jakob_nesnes
Try this:
DateTime.Now.AddHours(-1).Tostring("HH:mm")
2 Likes
sarathi125
(Parthasarathi)
November 15, 2019, 8:06am
3
@Jakob_nesnes ,
Try like this,
Datetime.Now.AddHours(-1).ToString("HH:mm")
1 Like
You can use PadLeft to add zeroes.
Datetime.Now.AddHours(-1).TimeOfDay.Hours.ToString.PadLeft(2, '0')
1 Like
system
(system)
Closed
November 18, 2019, 8:11am
6
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.