Click here to Skip to main content
13,702,535 members

Welcome to the Lounge

   

For discussing anything related to a software developer's life. Technical discussions are encouraged, but click here to ask your programming questions.

The Lounge is rated PG. If you're about to post something you wouldn't want your kid sister to read then don't post it. No flame wars, no abusive conduct, no programming questions and please don't post ads.
 
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 Rossel23hrs 15mins ago
professionalSander Rossel23hrs 15mins ago 
GeneralMy face is red Pin
John Simmons / outlaw programmer15-Sep-18 12:25
professionalJohn Simmons / outlaw programmer15-Sep-18 12:25 
GeneralRe: My face is red Pin
Lopatir15-Sep-18 19:19
memberLopatir15-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
John Simmons / outlaw programmer17-Sep-18 1:38
professionalJohn Simmons / outlaw programmer17-Sep-18 1:38 
GeneralThe things you learn Pin
Marc Clifton15-Sep-18 11:53
protectorMarc 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 4 days ago.

GeneralRe: The things you learn Pin
Mike Hankey15-Sep-18 13:51
professionalMike Hankey15-Sep-18 13:51 
GeneralRe: The things you learn Pin
Marc Clifton16-Sep-18 2:54
protectorMarc Clifton16-Sep-18 2:54 
GeneralRe: The things you learn Pin
R. Giskard Reventlov15-Sep-18 14:33
professionalR. Giskard Reventlov15-Sep-18 14:33 
GeneralRe: The things you learn Pin
BillWoodruff15-Sep-18 19:20
mentorBillWoodruff15-Sep-18 19:20 
GeneralRe: The things you learn Pin
Marc Clifton16-Sep-18 2:54
protectorMarc 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
memberMycroft 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
memberMycroft Holmes16-Sep-18 12:02 
GeneralRe: The things you learn Pin
Marc Clifton16-Sep-18 2:56
protectorMarc Clifton16-Sep-18 2:56 
GeneralRe: The things you learn Pin
Mycroft Holmes16-Sep-18 12:07
memberMycroft 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
memberMycroft Holmes16-Sep-18 20:37 
GeneralRe: The things you learn Pin
BillWoodruff15-Sep-18 19:29
mentorBillWoodruff15-Sep-18 19:29 
GeneralRe: The things you learn Pin
Marc Clifton16-Sep-18 2:58
protectorMarc 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.


Advertise | Privacy | Cookies | Terms of Service
Web01-2016 | 2.8.180906.1 | Last Updated 20 Sep 2018
Copyright © CodeProject, 1999-2018
All Rights Reserved.
Layout: fixed | fluid