Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. The Lounge
  3. So there I was...

So there I was...

Scheduled Pinned Locked Moved The Lounge
databasesql-serversysadminquestioncareer
27 Posts 18 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Ravi Bhavnani

    John Simmons / outlaw programmer wrote:

    I assumed that it would represent the number of seconds in the day (from midnight)

    I would have, too.  It's odd they chose the format they have, but at least it's ordinal and documented[^]. /ravi

    My new year resolution: 2048 x 1536 Home | Articles | My .NET bits | Freeware ravib(at)ravib(dot)com

    R Offline
    R Offline
    realJSOP
    wrote on last edited by
    #4

    I created an extension method to parse it...

    public static class ExtendTimeSpan
    {
    public static TimeSpan ParseFromFormattedInt(int value)
    {
    return new TimeSpan(0).ParseFromFormattedInt(value);
    }

    public static TimeSpan ParseFromFormattedInt(this TimeSpan span, int value)
    {
        TimeSpan result = new TimeSpan(0);
        string timeString = value.ToString();
        string padding    = new String('0', 6 - timeString.Length); 
        timeString = ((timeString.Length < 6) ? string.Concat(padding, timeString) : timeString).Insert(4, ":").Insert(2,":");
        try
        {
            result     = TimeSpan.ParseExact(timeString, "g", CultureInfo.CurrentCulture);
        }
        catch (Exception)
        {
        }
        return result;
    }
    

    }

    ".45 ACP - because shooting twice is just silly" - JSOP, 2010
    -----
    You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010
    -----
    When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013

    R R 2 Replies Last reply
    0
    • T Tim Carmichael

      If 235959 represents 23:59:59 and the type is 'int', how would they have a two digit hour for 3 AM? It seem reasonable that any time represented as a 6 character string without ":" delimiters, when converted to a 'int' would give the appropriate response. So.. a time of 00:00:01, when stripped of delimiters would give 000001 and converted to an 'int' would give... 1. So.. outside of the odd data type, what's the issue?

      R Offline
      R Offline
      realJSOP
      wrote on last edited by
      #5

      The issue is that it's an absurd way to represent the time. They're using an int data type, so the number of seconds past midnight would have made more sense, because it requires the same amount of storage space to store 1 as it does to store 1000. This means that in order to determine "the time", I had to write a method to parse the value instead of using

      TimeSpan span = TimeSpan.FromSeconds(1);

      ".45 ACP - because shooting twice is just silly" - JSOP, 2010
      -----
      You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010
      -----
      When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013

      H 1 Reply Last reply
      0
      • R realJSOP

        I created an extension method to parse it...

        public static class ExtendTimeSpan
        {
        public static TimeSpan ParseFromFormattedInt(int value)
        {
        return new TimeSpan(0).ParseFromFormattedInt(value);
        }

        public static TimeSpan ParseFromFormattedInt(this TimeSpan span, int value)
        {
            TimeSpan result = new TimeSpan(0);
            string timeString = value.ToString();
            string padding    = new String('0', 6 - timeString.Length); 
            timeString = ((timeString.Length < 6) ? string.Concat(padding, timeString) : timeString).Insert(4, ":").Insert(2,":");
            try
            {
                result     = TimeSpan.ParseExact(timeString, "g", CultureInfo.CurrentCulture);
            }
            catch (Exception)
            {
            }
            return result;
        }
        

        }

        ".45 ACP - because shooting twice is just silly" - JSOP, 2010
        -----
        You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010
        -----
        When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013

        R Offline
        R Offline
        Ravi Bhavnani
        wrote on last edited by
        #6

        :thumbsup: /ravi

        My new year resolution: 2048 x 1536 Home | Articles | My .NET bits | Freeware ravib(at)ravib(dot)com

        1 Reply Last reply
        0
        • R realJSOP

          ...exploring the msdb.dbo.sysschedules table in Sql Server, and one of the columns is called active_end_time of type int. When I saw the definition, I assumed that it would represent the number of seconds in the day (from midnight). I was wrong (and surprised, bewildered, and downright annoyed) when presented with the reality of the situation. The value returned was 235959 which far exceeds the number of seconds in a day (86400). In reality, it is a numeric representation of "23:59:59". WTF Microsoft!!!! What rocket scientist decided that this was a valid way to represent a time-of-freakin-day?! Even worse, they don't use two-digit hours, so "30000" represents "3 am". Also, "0" indicates midnight, so how do they represent 1 second past midnight? (I don't know because none of existing the job schedules have a time like that.) EDIT ================= Out of curiosity, I added a job with a schedule that starts at 00:00:01, and the value stored in table is "1".

          ".45 ACP - because shooting twice is just silly" - JSOP, 2010
          -----
          You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010
          -----
          When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013

          OriginalGriffO Offline
          OriginalGriffO Offline
          OriginalGriff
          wrote on last edited by
          #7

          It's silly, but I see the logic: it's human readable, as well as easily calculated for matches. "Number of seconds since midnight" is a better solution except for the human readable bit: when is 52642? Can you tell exactly and easily without a calculator? Or is it easier to just look at 143722 and know immediately when it is? The silliness if you think about it is having 60 seconds to the minute, 60 minutes to the hour, 24 hours to the day - instead of using a minute that was about 50% longer than the current one, made up of 100 (slightly longer) seconds, and having 1000 new-minutes in a day. We could call it "Stardate" and annoy rabid Trekkies.

          Bad command or file name. Bad, bad command! Sit! Stay! Staaaay... AntiTwitter: @DalekDave is now a follower!

          "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
          "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

          D R L N D 5 Replies Last reply
          0
          • OriginalGriffO OriginalGriff

            It's silly, but I see the logic: it's human readable, as well as easily calculated for matches. "Number of seconds since midnight" is a better solution except for the human readable bit: when is 52642? Can you tell exactly and easily without a calculator? Or is it easier to just look at 143722 and know immediately when it is? The silliness if you think about it is having 60 seconds to the minute, 60 minutes to the hour, 24 hours to the day - instead of using a minute that was about 50% longer than the current one, made up of 100 (slightly longer) seconds, and having 1000 new-minutes in a day. We could call it "Stardate" and annoy rabid Trekkies.

            Bad command or file name. Bad, bad command! Sit! Stay! Staaaay... AntiTwitter: @DalekDave is now a follower!

            D Offline
            D Offline
            dandy72
            wrote on last edited by
            #8

            OriginalGriff wrote:

            It's silly, but I see the logic

            The logic is that you don't invent yet another representation for time values... Who felt this was necessary?

            J 1 Reply Last reply
            0
            • OriginalGriffO OriginalGriff

              It's silly, but I see the logic: it's human readable, as well as easily calculated for matches. "Number of seconds since midnight" is a better solution except for the human readable bit: when is 52642? Can you tell exactly and easily without a calculator? Or is it easier to just look at 143722 and know immediately when it is? The silliness if you think about it is having 60 seconds to the minute, 60 minutes to the hour, 24 hours to the day - instead of using a minute that was about 50% longer than the current one, made up of 100 (slightly longer) seconds, and having 1000 new-minutes in a day. We could call it "Stardate" and annoy rabid Trekkies.

              Bad command or file name. Bad, bad command! Sit! Stay! Staaaay... AntiTwitter: @DalekDave is now a follower!

              R Offline
              R Offline
              realJSOP
              wrote on last edited by
              #9

              OriginalGriff wrote:

              "Number of seconds since midnight" is a better solution except for the human readable bit:

              It's a numeric value in a database - it doesn't have to be human readable as the actual time. It requires parsing to be used, especially if you want to perform math with it (the SQL required to parse this would be a mild nightmare), and almost always when you simply want to display it. I stand by my original claim that it's absurd.

              ".45 ACP - because shooting twice is just silly" - JSOP, 2010
              -----
              You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010
              -----
              When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013

              M 1 Reply Last reply
              0
              • R realJSOP

                ...exploring the msdb.dbo.sysschedules table in Sql Server, and one of the columns is called active_end_time of type int. When I saw the definition, I assumed that it would represent the number of seconds in the day (from midnight). I was wrong (and surprised, bewildered, and downright annoyed) when presented with the reality of the situation. The value returned was 235959 which far exceeds the number of seconds in a day (86400). In reality, it is a numeric representation of "23:59:59". WTF Microsoft!!!! What rocket scientist decided that this was a valid way to represent a time-of-freakin-day?! Even worse, they don't use two-digit hours, so "30000" represents "3 am". Also, "0" indicates midnight, so how do they represent 1 second past midnight? (I don't know because none of existing the job schedules have a time like that.) EDIT ================= Out of curiosity, I added a job with a schedule that starts at 00:00:01, and the value stored in table is "1".

                ".45 ACP - because shooting twice is just silly" - JSOP, 2010
                -----
                You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010
                -----
                When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013

                V Offline
                V Offline
                Vark111
                wrote on last edited by
                #10

                haha, At the company I work for, we have several systems that use delivery dates as primary keys/foreign keys. So we decided on using ints for this as well. Today is the integer value 20171004

                1 Reply Last reply
                0
                • R realJSOP

                  I created an extension method to parse it...

                  public static class ExtendTimeSpan
                  {
                  public static TimeSpan ParseFromFormattedInt(int value)
                  {
                  return new TimeSpan(0).ParseFromFormattedInt(value);
                  }

                  public static TimeSpan ParseFromFormattedInt(this TimeSpan span, int value)
                  {
                      TimeSpan result = new TimeSpan(0);
                      string timeString = value.ToString();
                      string padding    = new String('0', 6 - timeString.Length); 
                      timeString = ((timeString.Length < 6) ? string.Concat(padding, timeString) : timeString).Insert(4, ":").Insert(2,":");
                      try
                      {
                          result     = TimeSpan.ParseExact(timeString, "g", CultureInfo.CurrentCulture);
                      }
                      catch (Exception)
                      {
                      }
                      return result;
                  }
                  

                  }

                  ".45 ACP - because shooting twice is just silly" - JSOP, 2010
                  -----
                  You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010
                  -----
                  When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013

                  R Offline
                  R Offline
                  Richard Deeming
                  wrote on last edited by
                  #11

                  No need to mess around with strings:

                  public static class ExtendTimeSpan
                  {
                  public static TimeSpan ParseFromFormattedInt(int value)
                  {
                  int hours = Math.DivRem(value, 10000, out value);
                  int minutes = Math.DivRem(value, 100, out value);
                  int seconds = value + minutes * 60 + hours * 3600;
                  return TimeSpan.FromSeconds(seconds);
                  }

                  public static TimeSpan ParseFromFormattedInt(this TimeSpan span, int value)
                  {
                      return ParseFromFormattedInt(value);
                  }
                  

                  }

                  Or, in SQL (2012 or later):

                  SELECT
                  TIMEFROMPARTS(active_end_time / 10000, (active_end_time / 100) % 100, active_end_time % 100, 0, 0)
                  FROM
                  msdb.dbo.sysschedules
                  ;


                  "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

                  R 2 Replies Last reply
                  0
                  • OriginalGriffO OriginalGriff

                    It's silly, but I see the logic: it's human readable, as well as easily calculated for matches. "Number of seconds since midnight" is a better solution except for the human readable bit: when is 52642? Can you tell exactly and easily without a calculator? Or is it easier to just look at 143722 and know immediately when it is? The silliness if you think about it is having 60 seconds to the minute, 60 minutes to the hour, 24 hours to the day - instead of using a minute that was about 50% longer than the current one, made up of 100 (slightly longer) seconds, and having 1000 new-minutes in a day. We could call it "Stardate" and annoy rabid Trekkies.

                    Bad command or file name. Bad, bad command! Sit! Stay! Staaaay... AntiTwitter: @DalekDave is now a follower!

                    L Offline
                    L Offline
                    Lost User
                    wrote on last edited by
                    #12

                    Reminds me of an old SNL sketch about new metric time. 100 (current duration) seconds in a metric minute. 100 metric minutes in a metric hour. 100 metric hours in a metric day.

                    Quote:

                    The Metric Leisure Week will be composed of three days. Yes, only three days. Monday, Tuesday and Wednesday will become one day known as Mwensday or in decabet: Mwen. Thursday, Friday and Saturday will become Saturthurs, or in decabet: Turth. And Sunday, our traditional day of rest, will remain Sunday. Three days: Mwen, Thurth and Sunday.

                    J 1 Reply Last reply
                    0
                    • L Lost User

                      Reminds me of an old SNL sketch about new metric time. 100 (current duration) seconds in a metric minute. 100 metric minutes in a metric hour. 100 metric hours in a metric day.

                      Quote:

                      The Metric Leisure Week will be composed of three days. Yes, only three days. Monday, Tuesday and Wednesday will become one day known as Mwensday or in decabet: Mwen. Thursday, Friday and Saturday will become Saturthurs, or in decabet: Turth. And Sunday, our traditional day of rest, will remain Sunday. Three days: Mwen, Thurth and Sunday.

                      J Offline
                      J Offline
                      Jorgen Andersson
                      wrote on last edited by
                      #13

                      Yes, it's a joke, but the French actually did it. Decimal time - Wikipedia[^] French Republican Calendar - Wikipedia[^]

                      Wrong is evil and must be defeated. - Jeff Ello

                      1 Reply Last reply
                      0
                      • R realJSOP

                        OriginalGriff wrote:

                        "Number of seconds since midnight" is a better solution except for the human readable bit:

                        It's a numeric value in a database - it doesn't have to be human readable as the actual time. It requires parsing to be used, especially if you want to perform math with it (the SQL required to parse this would be a mild nightmare), and almost always when you simply want to display it. I stand by my original claim that it's absurd.

                        ".45 ACP - because shooting twice is just silly" - JSOP, 2010
                        -----
                        You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010
                        -----
                        When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013

                        M Offline
                        M Offline
                        Mike Winiberg
                        wrote on last edited by
                        #14

                        Strikes me that this might be a hangover from the days when memory/disk was in short supply and storing an INT took 16 bits, compared with a 6 char string which took 48. If not directly so, then because the programmer who wrote the code had a history of working on such systems... (First release of SQL Server was 16bit, for OS/2 in 1989 I believe) There was a time when memory was severely constrained, not to mention thousands and thousands of times more expensive than it is now, and likewise processor/disk speed was much slower, so this kind of approach was needed. It's only recently that we have got used to a web page running in a browser using more computing power than an entire organisation once possessed to simply display an annoying pop-up ad with sound and video. 8)

                        J 1 Reply Last reply
                        0
                        • R realJSOP

                          ...exploring the msdb.dbo.sysschedules table in Sql Server, and one of the columns is called active_end_time of type int. When I saw the definition, I assumed that it would represent the number of seconds in the day (from midnight). I was wrong (and surprised, bewildered, and downright annoyed) when presented with the reality of the situation. The value returned was 235959 which far exceeds the number of seconds in a day (86400). In reality, it is a numeric representation of "23:59:59". WTF Microsoft!!!! What rocket scientist decided that this was a valid way to represent a time-of-freakin-day?! Even worse, they don't use two-digit hours, so "30000" represents "3 am". Also, "0" indicates midnight, so how do they represent 1 second past midnight? (I don't know because none of existing the job schedules have a time like that.) EDIT ================= Out of curiosity, I added a job with a schedule that starts at 00:00:01, and the value stored in table is "1".

                          ".45 ACP - because shooting twice is just silly" - JSOP, 2010
                          -----
                          You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010
                          -----
                          When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013

                          G Offline
                          G Offline
                          GKP1992
                          wrote on last edited by
                          #15

                          May be they were just trying to avoid a couple of mod operations. :-D

                          I am not the one who knocks. I never knock. In fact, I hate knocking.

                          1 Reply Last reply
                          0
                          • M Mike Winiberg

                            Strikes me that this might be a hangover from the days when memory/disk was in short supply and storing an INT took 16 bits, compared with a 6 char string which took 48. If not directly so, then because the programmer who wrote the code had a history of working on such systems... (First release of SQL Server was 16bit, for OS/2 in 1989 I believe) There was a time when memory was severely constrained, not to mention thousands and thousands of times more expensive than it is now, and likewise processor/disk speed was much slower, so this kind of approach was needed. It's only recently that we have got used to a web page running in a browser using more computing power than an entire organisation once possessed to simply display an annoying pop-up ad with sound and video. 8)

                            J Offline
                            J Offline
                            jsc42
                            wrote on last edited by
                            #16

                            But no of secs in a day = 86400 (17 bits if signed int, 16 bits if unsigned int) However, 235959 needs 18 bits if signed int or 17 bits if unsigned int

                            M 1 Reply Last reply
                            0
                            • R realJSOP

                              ...exploring the msdb.dbo.sysschedules table in Sql Server, and one of the columns is called active_end_time of type int. When I saw the definition, I assumed that it would represent the number of seconds in the day (from midnight). I was wrong (and surprised, bewildered, and downright annoyed) when presented with the reality of the situation. The value returned was 235959 which far exceeds the number of seconds in a day (86400). In reality, it is a numeric representation of "23:59:59". WTF Microsoft!!!! What rocket scientist decided that this was a valid way to represent a time-of-freakin-day?! Even worse, they don't use two-digit hours, so "30000" represents "3 am". Also, "0" indicates midnight, so how do they represent 1 second past midnight? (I don't know because none of existing the job schedules have a time like that.) EDIT ================= Out of curiosity, I added a job with a schedule that starts at 00:00:01, and the value stored in table is "1".

                              ".45 ACP - because shooting twice is just silly" - JSOP, 2010
                              -----
                              You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010
                              -----
                              When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013

                              K Offline
                              K Offline
                              kalberts
                              wrote on last edited by
                              #17

                              If you hadn't mentioned SQL (obligatory Geek & Poke: Simply exåøaomed: SQL[^] I would have understood your worries. Historically, databases (and Cobol :-)) primary belongs in the domain of administration, management and economy. You work with dollars and cents, maybe tenth of a cent as well, but that is exact. If you split a bill of $3.30 on three persons, $1.10 on each, and collect the three $3.30 for giving it to the taxi driver, he receives exactly $3.30. If you do it in the engineering style floating point numbers, the amount that the taxi driver rececives makes you associate to Pentium FDIV bug - Wikipedia[^]. Accountants are as mad at floating point inexactness as engineers are at the Intel bug! So, at least since around 1960, developers of business software (as well as computer manufacturers making machines for executing that software) have been storing values in Binary-coded decimal[^] (BCD) format: Each binary digit takes up 4 bits. Since this gives 16 possibilities, the excess six are usually defined to represent numeric sign (+/-), currency symbol etc. Note that conversion from ASCII to BCD digits is a simple masking (AND) operation, from BCD to ASCII setting a couple bits (OR). Most machines/libraries can handle BCD both eight bits to the digit (after simple ASCII masking) and four bits to the digit (sometimes called 'packed BCD'), for space saving. Several CPU architectures support arithmetic operations on BCD values - although some not fully: I was working with a machine that had hardware (well, actually it was microcoded) add, subtract, and multiply of BCD. Dynamic analysis of real-life Cobol applications showed that BCD division was almost never done. The cost of implementing BCD divide in hardware was too high to justify it, so the instruction code was defined, causing an "Unimplemented instruction code" interrupt, and an interrupt handler performed the operation in software. (Very slow,

                              1 Reply Last reply
                              0
                              • J jsc42

                                But no of secs in a day = 86400 (17 bits if signed int, 16 bits if unsigned int) However, 235959 needs 18 bits if signed int or 17 bits if unsigned int

                                M Offline
                                M Offline
                                Mike Winiberg
                                wrote on last edited by
                                #18

                                You are right, of course. I don't know how things were/are stored internally in SQL Server, but even in 16 bit stuff you could usually store 32bit INTs, which is still smaller than the 48bits needed for "235959". You could usually manipulate DWORDS (32 bits) with single machine instructions, where as to manipulate "235959" would require a whole subroutine. Hence my comment. These days no-one thinks twice (or even once) about using a few megabytes of inefficient code to splurge something onto your browser window, but I suspect in the highly competitive world of high-end/large/NoSQL database implementations where speed is often of the essence, such apparently strange optimisations are still being used.

                                L 1 Reply Last reply
                                0
                                • M Mike Winiberg

                                  You are right, of course. I don't know how things were/are stored internally in SQL Server, but even in 16 bit stuff you could usually store 32bit INTs, which is still smaller than the 48bits needed for "235959". You could usually manipulate DWORDS (32 bits) with single machine instructions, where as to manipulate "235959" would require a whole subroutine. Hence my comment. These days no-one thinks twice (or even once) about using a few megabytes of inefficient code to splurge something onto your browser window, but I suspect in the highly competitive world of high-end/large/NoSQL database implementations where speed is often of the essence, such apparently strange optimisations are still being used.

                                  L Offline
                                  L Offline
                                  Lost User
                                  wrote on last edited by
                                  #19

                                  Mike Winiberg wrote:

                                  You are right, of course. I don't know how things were/are stored internally in SQL Server, but even in 16 bit stuff you could usually store 32bit INTs, which is still smaller than the 48bits needed for "235959".

                                  You would only need 48bits if you were storing as text. 2,147,483,647 can be stored in a signed 32bit INT.

                                  Michael Martin Australia "I controlled my laughter and simple said "No,I am very busy,so I can't write any code for you". The moment they heard this all the smiling face turned into a sad looking face and one of them farted. So I had to leave the place as soon as possible." - Mr.Prakash One Fine Saturday. 24/04/2004

                                  1 Reply Last reply
                                  0
                                  • OriginalGriffO OriginalGriff

                                    It's silly, but I see the logic: it's human readable, as well as easily calculated for matches. "Number of seconds since midnight" is a better solution except for the human readable bit: when is 52642? Can you tell exactly and easily without a calculator? Or is it easier to just look at 143722 and know immediately when it is? The silliness if you think about it is having 60 seconds to the minute, 60 minutes to the hour, 24 hours to the day - instead of using a minute that was about 50% longer than the current one, made up of 100 (slightly longer) seconds, and having 1000 new-minutes in a day. We could call it "Stardate" and annoy rabid Trekkies.

                                    Bad command or file name. Bad, bad command! Sit! Stay! Staaaay... AntiTwitter: @DalekDave is now a follower!

                                    N Offline
                                    N Offline
                                    Nicholas Marty
                                    wrote on last edited by
                                    #20

                                    OriginalGriff wrote:

                                    The silliness if you think about it is having 60 seconds to the minute, 60 minutes to the hour, 24 hours to the day - instead of using a minute that was about 50% longer than the current one, made up of 100 (slightly longer) seconds, and having 1000 new-minutes in a day.

                                    There is a rationale behind using 24 / 60 / 60. It's the same as the one with 360 degrees instead 100. 60 and 24 (and by extension 3600 is easier to divide than 100. 12 and 24 are easier to divide than 10 or 20, and 60 is easier to divide than 100. You can divide 10 by 1, 2, 5, 10 You can divide 12 by 1, 2, 3, 4, 6, 12 You can divide 20 by 1, 2, 4, 5, 10, 20 You can divide 24 by 1, 2, 3, 4, 6, 8, 12, 24 You can divide 60 by 1, 2, 3, 4, 5, 6, 10, 12, 15, 20, 30, 60 without running into decimal places You can divide 100 by 1, 2, 4, 5, 10, 20, 25, 50, 100 without running into decimal places The most important ones of these is probably to be able to divide by 2, 3 and 4 without having a remainder.

                                    1 Reply Last reply
                                    0
                                    • R Richard Deeming

                                      No need to mess around with strings:

                                      public static class ExtendTimeSpan
                                      {
                                      public static TimeSpan ParseFromFormattedInt(int value)
                                      {
                                      int hours = Math.DivRem(value, 10000, out value);
                                      int minutes = Math.DivRem(value, 100, out value);
                                      int seconds = value + minutes * 60 + hours * 3600;
                                      return TimeSpan.FromSeconds(seconds);
                                      }

                                      public static TimeSpan ParseFromFormattedInt(this TimeSpan span, int value)
                                      {
                                          return ParseFromFormattedInt(value);
                                      }
                                      

                                      }

                                      Or, in SQL (2012 or later):

                                      SELECT
                                      TIMEFROMPARTS(active_end_time / 10000, (active_end_time / 100) % 100, active_end_time % 100, 0, 0)
                                      FROM
                                      msdb.dbo.sysschedules
                                      ;


                                      "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

                                      R Offline
                                      R Offline
                                      realJSOP
                                      wrote on last edited by
                                      #21

                                      Richard Deeming wrote:

                                      Or, in SQL (2012 or later):

                                      This is 2008R2... :/

                                      ".45 ACP - because shooting twice is just silly" - JSOP, 2010
                                      -----
                                      You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010
                                      -----
                                      When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013

                                      1 Reply Last reply
                                      0
                                      • R realJSOP

                                        ...exploring the msdb.dbo.sysschedules table in Sql Server, and one of the columns is called active_end_time of type int. When I saw the definition, I assumed that it would represent the number of seconds in the day (from midnight). I was wrong (and surprised, bewildered, and downright annoyed) when presented with the reality of the situation. The value returned was 235959 which far exceeds the number of seconds in a day (86400). In reality, it is a numeric representation of "23:59:59". WTF Microsoft!!!! What rocket scientist decided that this was a valid way to represent a time-of-freakin-day?! Even worse, they don't use two-digit hours, so "30000" represents "3 am". Also, "0" indicates midnight, so how do they represent 1 second past midnight? (I don't know because none of existing the job schedules have a time like that.) EDIT ================= Out of curiosity, I added a job with a schedule that starts at 00:00:01, and the value stored in table is "1".

                                        ".45 ACP - because shooting twice is just silly" - JSOP, 2010
                                        -----
                                        You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010
                                        -----
                                        When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013

                                        E Offline
                                        E Offline
                                        englebart
                                        wrote on last edited by
                                        #22

                                        I worked on a system where date was stored as (year << 16) | (month << 8) | (day-of-month) When looking at the raw data, we used hex. 07E10A05 (07E1-0A-05) would be today's date: 2017-10-05. Sorted correctly in the indexes and was very easy to interpret for month and day. I am sure that the implementer of the SQL field was trying to make it user friendly for display. I guess it HAS to be interpreted based on the local system/DB time zone.

                                        1 Reply Last reply
                                        0
                                        • R Richard Deeming

                                          No need to mess around with strings:

                                          public static class ExtendTimeSpan
                                          {
                                          public static TimeSpan ParseFromFormattedInt(int value)
                                          {
                                          int hours = Math.DivRem(value, 10000, out value);
                                          int minutes = Math.DivRem(value, 100, out value);
                                          int seconds = value + minutes * 60 + hours * 3600;
                                          return TimeSpan.FromSeconds(seconds);
                                          }

                                          public static TimeSpan ParseFromFormattedInt(this TimeSpan span, int value)
                                          {
                                              return ParseFromFormattedInt(value);
                                          }
                                          

                                          }

                                          Or, in SQL (2012 or later):

                                          SELECT
                                          TIMEFROMPARTS(active_end_time / 10000, (active_end_time / 100) % 100, active_end_time % 100, 0, 0)
                                          FROM
                                          msdb.dbo.sysschedules
                                          ;


                                          "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

                                          R Offline
                                          R Offline
                                          realJSOP
                                          wrote on last edited by
                                          #23

                                          I knew a math way was possible. This can also be extended to the dates that are stored in the same fashion: Given an int value of 99991231:

                                          int year = Math.DivRem(value, 10000, out value);
                                          int month = Math.DivRem(value, 100, out value);
                                          int day = value;
                                          return new DateTime(year, month, day);

                                          would yield a datetime of 12/31/9999.

                                          ".45 ACP - because shooting twice is just silly" - JSOP, 2010
                                          -----
                                          You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010
                                          -----
                                          When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013

                                          R 1 Reply Last reply
                                          0
                                          Reply
                                          • Reply as topic
                                          Log in to reply
                                          • Oldest to Newest
                                          • Newest to Oldest
                                          • Most Votes


                                          • Login

                                          • Don't have an account? Register

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • World
                                          • Users
                                          • Groups