Converting int seconds to datetime or formated string

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Pat Brown

    #1

    Converting int seconds to datetime or formated string

    I am pulling an integer value of the amount of seconds since 12:00 am from a
    SQL Server DB. I want to convert this integer into a formated string or
    datetime to display a legible time of day. Are there any built in methods in
    the .NET framework that will accomplish this. If not, any other suggestion
    about creating a method to do this would be appretiated.
    Thanks
  • Arran Pearce

    #2
    Re: Converting int seconds to datetime or formated string

    DateTime dt = new DateTime(year, month, day, 0, 0, 0);

    dt.Add(new TimeSpan(0,0,nu mberOfSecs);

    Is that what you mean?



    "Pat Brown" <PatBrown@discu ssions.microsof t.com> wrote in message
    news:488A7177-9A76-42EC-AFE6-A72F89901F12@mi crosoft.com...[color=blue]
    >I am pulling an integer value of the amount of seconds since 12:00 am from
    >a
    > SQL Server DB. I want to convert this integer into a formated string or
    > datetime to display a legible time of day. Are there any built in methods
    > in
    > the .NET framework that will accomplish this. If not, any other
    > suggestion
    > about creating a method to do this would be appretiated.
    > Thanks[/color]


    Comment

    • Chris Priede

      #3
      Re: Converting int seconds to datetime or formated string

      Pat Brown wrote:[color=blue]
      > I am pulling an integer value of the amount of seconds
      > since 12:00 am[/color]

      Since you didn't specify what date, I am going to assume it is always from
      12:00am today.
      [color=blue]
      > I want to convert this integer into a formated string or
      > datetime to display a legible time of day.[/color]

      A few ideas to get you started:


      DateTime foo = DateTime.Now.Da te.AddSeconds(s econds);

      string foo = string.Format(" {0:00}:{1:00}", seconds / 3600, seconds % 3600 /
      60);


      --
      Chris Priede


      Comment

      Working...