• (cs) in reply to operagost
    operagost:
    The real WTF is the Census Bureau. All but one (arguably two) of the questions on that form are unconstitutional. Why do they need to know if I own my house, or my phone number, to make a head count for the House of Representatives? Why do they need to know my race-- have they not heard of the 16th amendment?

    What bugs me is that the instructions told me to send it in the day I got it... But asked me questions about who WAS living at my address on April 1st. How the hell should I know?

    I also refuse to answer the race questions. All of the people in my house will be down as "other: human".

  • csrster (unregistered)

    I was doing a little php scripting recently and was surprised to find that the easiest way to get some date-time conversions down was, indeed, to query the database I was connected to in any case. Apparently a decent date-time-api for php is on the way in php6 or some such.

  • nah (unregistered) in reply to dguthurts
    dguthurts:
    Ha!. Not complicated enough. If our "lead" developers had their way, you'd have to call a remote service to make the database call.

    "lead" is probably reference to the metal. You're just all mispronouncing it and assume they should be "leading" you instead of pulling you down.

  • (cs) in reply to Paul R
    Paul R:
    The Constitution trumps any act of Congress, since the Constitution created and empowers Congress.

    Constitution of the United States, Section 1, Article 2: Enumeration shall be made within three Years after the first Meeting of the Congress of the United States, and within every subsequent Term of ten Years, in such Manner as they shall by Law direct.

    Enumeration means counting, not a detailed survey. You don't even have to give your name. Just the number of people where you live.

    That section also lists conditions of ownership (whether you're free or a slave) and racial distinctions (whether you're Indian or of European descent). Socioeconomic circumstances, in other words.

    If the Constitution does not explicitly give Congress the power to do something, they can't (legally) do it.
    The Constitution:
    Section 8 The Congress shall have Power To lay and collect Taxes, Duties, Imposts and Excises, to pay the Debts and provide for the common Defence and general Welfare of the United States; but all Duties, Imposts and Excises shall be uniform throughout the United States; .... To make all Laws which shall be necessary and proper for carrying into Execution the foregoing Powers, and all other Powers vested by this Constitution in the Government of the United States, or in any Department or Officer thereof.

    But don't look at me; I live in one of the few countries in the world not to bother with a written constitution.

  • (cs)

    /* The real WTF: it should be a stored proc, so it runs faster against our advanced code - yes it actually runs */

    CREATE PROCEDURE DATEDIFF @start datetime, @end datetime, @time_frame char, @days int AS
    
    SET @days = 0
    
    WHILE (@start < @end) BEGIN
    	SET @start = @start + 1
    	SET @days = @days + 1
    END
    
    IF (@time_frame = 'h') SET @days = @days * 24
    IF (@time_frame = 'm') SET @days = @days * 24 * 60
    IF (@time_frame = 's') SET @days = @days * 24 * 60 * 60
    
    SELECT @days AS [date_diff_result]
  • Steve the Cynic (unregistered) in reply to Massive Debt
    Massive Debt:
    SSNs may not fill the whole number space. I believe that the first 3 digits describe US states. So, they are limited to less than the 1,000 possibilities. Also, I've never seen a zero in an SSN.

    When I had a US SSN, it had three zeros, but not all together in a single clump.

  • 10-T (unregistered)

    TRWTF is the "birth date and SSN" thing as opposed to embedding the former in the latter. The way the did it here is a bit WTFy too, as they used YYMMDD format and thus post-2000 births have the 20 added to month... but heck, at least we have a check digit in there.

  • M Buckler (unregistered) in reply to BF

    I agree absolutely! For example I always use calls to the database to perform the kinds of calculations that I put into my database unit test scripts that will run against a sql server database. I don't try to use the language I'm scripting the tests in.

  • (cs) in reply to Massive Debt
    Massive Debt:
    justsomedude:
    Hatterson:
    The relationship between SSNs and people is *supposed* to be 1:1 although in practice (do to change someone's number for various reasons) it ends up being many:1

    The one thing it is not is 1:many

    Simply because I use (illegally I might add) someone else's SSN doesn't mean it still isn't an identifier unique to them.

    Are you sure about that? Let's see, SSNs are of the form ###-##-####, which means 1,000,000,000 unique numbers. If SSN's are never recycled, how many years do you think they last from inception to exhaustion?

    SSNs may not fill the whole number space. I believe that the first 3 digits describe US states. So, they are limited to less than the 1,000 possibilities. Also, I've never seen a zero in an SSN.

    What?? My SSN is 033-65-0856. That's 3 zeroes!

  • The SuperFreek (unregistered) in reply to partisan
    partisan:
    Lewis Crawford:
    The US Census Bureau beats this WTF: They make every citizen calculate their own DateDiff by making them enter their age as well as their birth date. No DateDiff needed by the Census Bureau.

    TRWTF is they ask you how many people are in your household on April 1 . . . In March.

    You can always wait until April 1 to send it in.

  • The SuperFreek (unregistered) in reply to Leo
    Leo:
    Anon:
    operagost:
    The real WTF is the Census Bureau. All but one (arguably two) of the questions on that form are unconstitutional. Why do they need to know if I own my house, or my phone number, to make a head count for the House of Representatives? Why do they need to know my race-- have they not heard of the 16th amendment?

    At least it's better than Clinton's ridiculous multi-page survey.

    I shouldn't feed an obvious troll, but here:

    http://2010.census.gov/2010census/how/interactive-form.php

    That should answers your questions, but I suspect that you don't care what the answers are because that might conflict with your tin-foil hat world view.

    Um, you're completely missing the point. Just because they say they want it doesn't make it any more constitutional.

    See also http://2010.census.gov/2010census/why/constitutional.php.

  • Hatterson (unregistered) in reply to toth
    toth:
    Massive Debt:
    justsomedude:
    Hatterson:
    The relationship between SSNs and people is *supposed* to be 1:1 although in practice (do to change someone's number for various reasons) it ends up being many:1

    The one thing it is not is 1:many

    Simply because I use (illegally I might add) someone else's SSN doesn't mean it still isn't an identifier unique to them.

    Are you sure about that? Let's see, SSNs are of the form ###-##-####, which means 1,000,000,000 unique numbers. If SSN's are never recycled, how many years do you think they last from inception to exhaustion?

    SSNs may not fill the whole number space. I believe that the first 3 digits describe US states. So, they are limited to less than the 1,000 possibilities. Also, I've never seen a zero in an SSN.

    What?? My SSN is 033-65-0856. That's 3 zeroes!

    That's actually only 2 zeros.

  • (cs) in reply to Hatterson
    Hatterson:
    toth:
    Massive Debt:
    justsomedude:
    Hatterson:
    The relationship between SSNs and people is *supposed* to be 1:1 although in practice (do to change someone's number for various reasons) it ends up being many:1

    The one thing it is not is 1:many

    Simply because I use (illegally I might add) someone else's SSN doesn't mean it still isn't an identifier unique to them.

    Are you sure about that? Let's see, SSNs are of the form ###-##-####, which means 1,000,000,000 unique numbers. If SSN's are never recycled, how many years do you think they last from inception to exhaustion?

    SSNs may not fill the whole number space. I believe that the first 3 digits describe US states. So, they are limited to less than the 1,000 possibilities. Also, I've never seen a zero in an SSN.

    What?? My SSN is 033-65-0856. That's 3 zeroes!

    That's actually only 2 zeros.

    Huh? It's clearly 3.

  • Chris the Developer (unregistered)

    I can't believe nobody has paid any attention to MySQL's delicious interval syntax.

    (bill_timestamp + INTERVAL 2 WEEK) AS bill_due

  • Hatterson (unregistered) in reply to Anon Ymous
    Anon Ymous:
    Hatterson:
    The relationship between SSNs and people is *supposed* to be 1:1 although in practice (do to change someone's number for various reasons) it ends up being many:1

    The one thing it is not is 1:many

    Simply because I use (illegally I might add) someone else's SSN doesn't mean it still isn't an identifier unique to them.

    An insurance company in the US has absolutely no need for a social security number whatsoever, nor must you have one in order to buy insurance. If the insurance company asks me for my social security number and I refuse to give it to them, they'll end up putting garbage in the field (it's required because an ignoramus assumed it must be unique and made it the key).

    It is not illegal to provide someone else's social security number unless you are attempting to represent yourself as that individual. (i.e. If I give them 123-45-6789 to protect my privacy and all my other information is true and correct, then I haven't committed a crime whether or not it happens to be the real SSN of someone unknown to me.)

    I wasn't meaning to comment on whether the company should or shouldn't ask for your SSN. I'm of the personal belief that they shouldn't need it, but honestly I don't really care about it so I'm not worried.

    In terms of my comment about using another person's SSN, I had meant representing someone else via a SSN. Using an SSN as a primary/unique key in a database is a completely different story than an SSN being a unique identifier for a person in general.

    And in regards to the comments about a limited number of SSNs available. Yes, that's accurate, but we're still a ways off..."About 360 million Social Security numbers have been issued to date, 211 million of which are "active," i.e., the holders are still breathing. Since there are about a billion possible numbers (actually 999 million, since nobody seems to want the 000 series), we'll be halfway into the next century before it's time to panic."

    The bigger issue with SS is running out of money, not numbers.

  • ExOttoyuhr (unregistered)

    MUMPS is strange, but don't call it primitive. It is to programming languages as Cthulhu is to people: disturbing appearance, humanoid form^W^Wintegrated SQL server, psychic powers^W^Wrobust internal functions, and wings^Wgreat performance.

    Dates are stored internally as days since December 31, 1840 (don't ask); time, in seconds since midnight. Functions built into the language convert to and from the Gregorian calendar and Julian day; see here and here for two such functions.

    Full disclosure: I used to work for the company in "A Case of the MUMPS," and after leaving them, I remembered that I spent most of my time working on VB and did most of my productive work in MUMPS -- and joined Intersystems, the vendor of Caché. MUMPS syntax is pretty strange and has potential to be much stranger, but it's very powerful once you get used to it, and the platform underneath is extremely robust. (Again like Cthulhu.)

  • (cs)

    Everybody knows that database date routines are the most accurate...

  • (cs) in reply to ExOttoyuhr
    ExOttoyuhr:
    Dates are stored internally as days since December 31, 1840 (don't ask)...

    Supposedly it's because it would allow any (then) living U.S. citizen's birthdate to be represented as a positive number.

    See here.

  • Mike (unregistered)
    The relationship between SSNs and people is *supposed* to be 1:1 although in practice (do to change someone's number for various reasons) it ends up being many:1

    The one thing it is not is 1:many

    Simply because I use (illegally I might add) someone else's SSN doesn't mean it still isn't an identifier unique to them.

    Nope. Social Security Numbers are not unique indentifiers, nor were they ever intended to be that way. They are, in fact, 1:many.

  • Hatterson (unregistered) in reply to Mike
    Mike:
    The relationship between SSNs and people is *supposed* to be 1:1 although in practice (do to change someone's number for various reasons) it ends up being many:1

    The one thing it is not is 1:many

    Simply because I use (illegally I might add) someone else's SSN doesn't mean it still isn't an identifier unique to them.

    Nope. Social Security Numbers are not unique indentifiers, nor were they ever intended to be that way. They are, in fact, 1:many.

    The same SSN is not issue to multiple people.

    Therefore if I ask the question "Who does SSN 001-02-0003 belong to?" There will be, at most, one answer.

    I'm not talking about number of people who have claimed that as their SSN, I'm talking about who the government says that SSN should belong to.

    I guess in technicality a SSN does not identify an individual, but rather a Social Security account which, in turn, belongs to one individual, however the end result is the same

  • Madman1969 (unregistered) in reply to jasmine2501

    ಠ_ಠ

  • RV6 (unregistered) in reply to usitas

    I actually did thate. I had our server at the main office, connect to each of the branch sql server computers, and then log all the available drive space in a table. This was a SQL process that ran at night. It let us keep track of drive space on each of the branch computers (about 150 of them)

  • Ted (unregistered)

    I worked in a proprietary xml-syntax language that had a lot of things like this because those functions were later additions. Using SQL functions had been the proper way to do those things at the time because of this.

    They also broke horribly when a client required Oracle as a backend instead of MS SQL. Actually, that may have been the reason the datediff functions were added to the language, or at least the reason they became widespread knowledge around the office of 15 programmers.

  • Quirkafleeg (unregistered) in reply to 3lit3 prgmr
    3lit3 prgmr:
    This is clearly the result of an experienced coder who has had significant experience with Daylight Saving Time. When deploying .NET code to a variety of locations, Date math is notoriously prone to error. Finding the number of minutes between 3/7/2010 12:00 AM and 3/7/2010 6:00 PM returns different results depending on local system defaults and operating system configuration.
    You might do better to pick a date in March or October…
  • Quirkafleeg (unregistered) in reply to operagost
    operagost:
    The real WTF is the Census Bureau. All but one (arguably two) of the questions on that form are unconstitutional. Why do they need to know if I own my house, or my phone number, to make a head count for the House of Representatives? Why do they need to know my race-- have they not heard of the 16th amendment?

    At least it's better than Clinton's ridiculous multi-page survey.

    Religion: [ ] None [ ] Christian [ ] Hindu [ ] Muslim […] [✓ ] Other:  Jedi        

  • Don't Bother Asking (unregistered) in reply to frits
    frits:
    Aw isn't that cute. They let the DBA write some code.

    Not our DBAs... Frankly I'd be surprised if they knew what a database is. Or how to tie their shoelaces.

    Note:- this is not a dig at DBAs. I've worked with some damn good ones in the past.

    I miss them now.

  • inhibeo (unregistered) in reply to frits
    frits:
    Hatterson:
    toth:
    Massive Debt:
    justsomedude:
    Hatterson:
    The relationship between SSNs and people is *supposed* to be 1:1 although in practice (do to change someone's number for various reasons) it ends up being many:1

    The one thing it is not is 1:many

    Simply because I use (illegally I might add) someone else's SSN doesn't mean it still isn't an identifier unique to them.

    Are you sure about that? Let's see, SSNs are of the form ###-##-####, which means 1,000,000,000 unique numbers. If SSN's are never recycled, how many years do you think they last from inception to exhaustion?

    SSNs may not fill the whole number space. I believe that the first 3 digits describe US states. So, they are limited to less than the 1,000 possibilities. Also, I've never seen a zero in an SSN.

    What?? My SSN is 033-65-0856. That's 3 zeroes!

    That's actually only 2 zeros.

    Huh? It's clearly 3.

    Toth's one of them.

  • CantBeBotheredToSignIn (unregistered) in reply to SCSimmons
    SCSimmons:
    frits:
    Aw isn't that cute. They let the DBA write some code.
    Yah, you can just kiss my grits.

    OK, I'm just cranky at the moment, because of the application developers who are asking me to add a column to the primary key of a 1M row table. In production. They don't seem to like my idea of doing some kind of testing first. I know, those darn curmudgeon DBAs!

    Pfft, nothing could possibleye go wrong!

  • John Meyer (unregistered) in reply to Lewis Crawford
    Lewis Crawford:
    The US Census Bureau beats this WTF: They make every citizen calculate their own DateDiff by making them enter their age as well as their birth date. No DateDiff needed by the Census Bureau.

    So do a few thousand businesses online as well. But in one sense this could serve as a good age check (of the user) if you do it right.

  • (cs)

    Hmm. I wonder what happens if you run this on a computer that uses a different dateformat than the SQL server...

  • Design Pattern (unregistered) in reply to GalacticCowboy
    GalacticCowboy:
    Clearly, the next iteration (after having read "Refactoring", of course...) would look like this:
    public static int DateDiff(DateTime date1, DateTime date2, TimeDifference td)
    {
      string sql = string.Empty;
      string oper = string.Empty;
    (...)
          sql = "SECOND";
          break;
    (...)
    
    }
    

    I see what you did there!

    CAPTCHA: causa Not using prepared statements causas errors like this!

Leave a comment on “A Better Date Diff”

Log In or post as a guest

Replying to comment #:

« Return to Article