Click here to Skip to main content
15,896,063 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 11:14
professionalSander Rossel18-Sep-18 11:14 
GeneralRe: Pure purr... Pin
David O'Neil18-Sep-18 12:18
professionalDavid O'Neil18-Sep-18 12:18 
GeneralRe: Pure purr... Pin
Sander Rossel19-Sep-18 3:45
professionalSander Rossel19-Sep-18 3:45 
GeneralMy face is red Pin
#realJSOP15-Sep-18 12:25
professional#realJSOP15-Sep-18 12:25 
GeneralRe: My face is red Pin
lopatir15-Sep-18 19:19
lopatir15-Sep-18 19:19 
GeneralRe: My face is red Pin
Daniel Pfeffer15-Sep-18 19:33
professionalDaniel Pfeffer15-Sep-18 19:33 
GeneralRe: My face is red Pin
#realJSOP17-Sep-18 1:38
professional#realJSOP17-Sep-18 1:38 
GeneralThe things you learn Pin
Marc Clifton15-Sep-18 11:53
mvaMarc Clifton15-Sep-18 11: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 13:51
mveMike Hankey15-Sep-18 13:51 
GeneralRe: The things you learn Pin
Marc Clifton16-Sep-18 2:54
mvaMarc Clifton16-Sep-18 2:54 
GeneralRe: The things you learn Pin
R. Giskard Reventlov15-Sep-18 14:33
R. Giskard Reventlov15-Sep-18 14:33 
GeneralRe: The things you learn Pin
BillWoodruff15-Sep-18 19:20
professionalBillWoodruff15-Sep-18 19:20 
GeneralRe: The things you learn Pin
Marc Clifton16-Sep-18 2:54
mvaMarc Clifton16-Sep-18 2:54 
GeneralRe: The things you learn Pin
Nelek16-Sep-18 21:37
protectorNelek16-Sep-18 21:37 
GeneralRe: The things you learn Pin
milo-xml17-Sep-18 2:02
professionalmilo-xml17-Sep-18 2:02 
GeneralRe: The things you learn Pin
Mycroft Holmes15-Sep-18 14:37
professionalMycroft Holmes15-Sep-18 14:37 
GeneralRe: The things you learn Pin
Slacker00715-Sep-18 23:40
professionalSlacker00715-Sep-18 23:40 
GeneralRe: The things you learn Pin
Sander Rossel16-Sep-18 1:19
professionalSander Rossel16-Sep-18 1:19 
GeneralRe: The things you learn Pin
Mycroft Holmes16-Sep-18 12:02
professionalMycroft Holmes16-Sep-18 12:02 
GeneralRe: The things you learn Pin
Marc Clifton16-Sep-18 2:56
mvaMarc Clifton16-Sep-18 2:56 
GeneralRe: The things you learn Pin
Mycroft Holmes16-Sep-18 12:07
professionalMycroft Holmes16-Sep-18 12:07 
GeneralRe: The things you learn Pin
Daniel Pfeffer16-Sep-18 20:18
professionalDaniel Pfeffer16-Sep-18 20:18 
GeneralRe: The things you learn Pin
Mycroft Holmes16-Sep-18 20:37
professionalMycroft Holmes16-Sep-18 20:37 
GeneralRe: The things you learn Pin
BillWoodruff15-Sep-18 19:29
professionalBillWoodruff15-Sep-18 19:29 
GeneralRe: The things you learn Pin
Marc Clifton16-Sep-18 2:58
mvaMarc Clifton16-Sep-18 2: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.