Click here to Skip to main content
14,458,109 members

Welcome to the Lounge

   

For discussing anything related to a software developer's life but is not for programming questions. Got a programming question?

The Lounge is rated Safe For Work. If you're about to post something inappropriate for a shared office environment, then don't post it. No ads, no abuse, and no programming questions. Trolling, (political, climate, religious or whatever) will result in your account being removed.
 
GeneralRe: Pure purr... Pin
Sander Rossel18-Sep-18 12:14
professionalSander Rossel18-Sep-18 12:14 
GeneralRe: Pure purr... Pin
David O'Neil18-Sep-18 13:18
professionalDavid O'Neil18-Sep-18 13:18 
GeneralRe: Pure purr... Pin
Sander Rossel19-Sep-18 4:45
professionalSander Rossel19-Sep-18 4:45 
GeneralMy face is red Pin
#realJSOP15-Sep-18 13:25
mva#realJSOP15-Sep-18 13:25 
GeneralRe: My face is red Pin
lopatir15-Sep-18 20:19
Memberlopatir15-Sep-18 20:19 
GeneralRe: My face is red Pin
Daniel Pfeffer15-Sep-18 20:33
professionalDaniel Pfeffer15-Sep-18 20:33 
GeneralRe: My face is red Pin
#realJSOP17-Sep-18 2:38
mva#realJSOP17-Sep-18 2:38 
GeneralThe things you learn Pin
Marc Clifton15-Sep-18 12:53
communityengineerMarc Clifton15-Sep-18 12:53 
I usually just save DateTime.Now for a DB transaction into some datetime field. If a report or UI needs to show the date/time, it's formatted accordingly, for example MM/dd/yyyy HH:mm:ss tt (for us US people).

So, I have a "When checked in" (start time) and I have a "When checked out" (stop time) for tracking employee hours worked. And I compute the hours/minutes/seconds worked basically as "check out time" - "check in time", displayed as "hh:mm:ss" (they don't work more than 24 hours, haha.)

So, on occasion, my time worked is off by 1 second comparing start time and stop time as hh:mm:ss.

Why? Because I of the millisecond component to date/time!

So I coded:
DateTime now = DateTime.Now;
now = now.AddMilliseconds(-now.Millisecond);

which works fine, particularly since the DB stores only 3 digits for the ms component, but out of curiosity, I google "getting DateTime without milliseconds" and come across this SO page.

And I wonder, WTF is all this crazy stuff they're doing. Lower down, I find my solution, and I read this:


The Millisecond property gives an integer between 0 and 999 (inclusive). So if the time of day before the operation was, say, 23:48:49.1234567, then that integer will be 123, and the time of day after the operation is 23:48:49.0004567. So it has not truncated to a whole number of seconds.


OMG. Seriously? OK, I guess that makes sense because underlying DateTime is actually Ticks, so subtracting off just the integer portion of the ms isn't necessarily going to give me an actual tick at exactly the second.

And to make things more complicated, there's the "Kind" -- Local, UTC, or undefined. Oh good grief.

So I'm going with the solution in one of the earlier SO posts that looks like this:

new DateTime(date.Ticks - (date.Ticks % resolution), date.Kind);

The lesson learned (over and over) is that you think something is simple, and it isn't.

The other lesson learned is, thank God for people smarter than me!
Latest Article - A Concise Overview of Threads

Learning to code with python is like learning to swim with those little arm floaties. It gives you undeserved confidence and will eventually drown you. - DangerBunny

Artificial intelligence is the only remedy for natural stupidity. - CDP1802


modified 15-Sep-18 17:59pm.

GeneralRe: The things you learn Pin
Mike Hankey15-Sep-18 14:51
professionalMike Hankey15-Sep-18 14:51 
GeneralRe: The things you learn Pin
Marc Clifton16-Sep-18 3:54
communityengineerMarc Clifton16-Sep-18 3:54 
GeneralRe: The things you learn Pin
R. Giskard Reventlov15-Sep-18 15:33
MemberR. Giskard Reventlov15-Sep-18 15:33 
GeneralRe: The things you learn Pin
BillWoodruff15-Sep-18 20:20
mveBillWoodruff15-Sep-18 20:20 
GeneralRe: The things you learn Pin
Marc Clifton16-Sep-18 3:54
communityengineerMarc Clifton16-Sep-18 3:54 
GeneralRe: The things you learn Pin
Nelek16-Sep-18 22:37
protectorNelek16-Sep-18 22:37 
GeneralRe: The things you learn Pin
milo-xml17-Sep-18 3:02
professionalmilo-xml17-Sep-18 3:02 
GeneralRe: The things you learn Pin
Mycroft Holmes15-Sep-18 15:37
MemberMycroft Holmes15-Sep-18 15:37 
GeneralRe: The things you learn Pin
Slacker00716-Sep-18 0:40
professionalSlacker00716-Sep-18 0:40 
GeneralRe: The things you learn Pin
Sander Rossel16-Sep-18 2:19
professionalSander Rossel16-Sep-18 2:19 
GeneralRe: The things you learn Pin
Mycroft Holmes16-Sep-18 13:02
MemberMycroft Holmes16-Sep-18 13:02 
GeneralRe: The things you learn Pin
Marc Clifton16-Sep-18 3:56
communityengineerMarc Clifton16-Sep-18 3:56 
GeneralRe: The things you learn Pin
Mycroft Holmes16-Sep-18 13:07
MemberMycroft Holmes16-Sep-18 13:07 
GeneralRe: The things you learn Pin
Daniel Pfeffer16-Sep-18 21:18
professionalDaniel Pfeffer16-Sep-18 21:18 
GeneralRe: The things you learn Pin
Mycroft Holmes16-Sep-18 21:37
MemberMycroft Holmes16-Sep-18 21:37 
GeneralRe: The things you learn Pin
BillWoodruff15-Sep-18 20:29
mveBillWoodruff15-Sep-18 20:29 
GeneralRe: The things you learn Pin
Marc Clifton16-Sep-18 3:58
communityengineerMarc Clifton16-Sep-18 3:58 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.