Closed Thread
Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: Odd Timestamp

  1. #1
    dirkfirst is offline Programming Expert
    Join Date
    May 2006
    Posts
    354
    Rep Power
    23

    Odd Timestamp

    I'm reading information from a database and came across this timestamp:

    1127836826

    What is that? How can I convert that to a normal date/time in C#? Is there a way to sort in SQL with this type of timestamp?

    I know this may belong in the database forum but I'm more concerened with converting it in C#.

  2. CODECALL Circuit advertisement
    Join Date
    Always
    Posts
    Many

     
  3. #2
    brackett is offline Programmer
    Join Date
    May 2006
    Posts
    192
    Rep Power
    22
    I'd guess it's a UNIX timestamp - meaning, the number of seconds since 1/1/1970. In this case, it converts to 9/27/05 16:00:26 (GMT).

    I don't think there's any built in conversion in .NET, so you'd just do it manually:
    Code:
    private static DateTime EPOCH = DateTime.Parse("1/1/1970")
    public static DateTime UnixToDateTime(int timestamp) {
       return (EPOCH + TimeSpan.FromSeconds(timestamp)).ToLocalTime()
    }

  4. #3
    Saint is offline Learning Programmer
    Join Date
    Aug 2006
    Posts
    63
    Rep Power
    0
    As for sorting you should be able to sort by that number in SQL.

    ORDER BY field ASC
    Hi >> Saint

  5. #4
    Jordan Guest
    You can also just use the UNIXTIMESTAMP() function of MySQL and I'm sure most other DBs have a function to conver t this as well.

  6. #5
    smith is offline Programmer
    Join Date
    Jun 2006
    Posts
    153
    Rep Power
    0
    Code:
    for (int i;;) {
       cout << "Smith";
    }

  7. #6
    Join Date
    Aug 2006
    Posts
    11,209
    Blog Entries
    6
    Rep Power
    101
    So acording to that converter that timestrap is:-
    Tue, 27 Sep 2005 16:00:26 UTC
    ??
    hmm it looks like an encrypted string! cool!

  8. #7
    dirkfirst is offline Programming Expert
    Join Date
    May 2006
    Posts
    354
    Rep Power
    23
    Thanks, that is exactly what that number is. Your C# code worked great brackett, thanks.

  9. #8
    NeedHelp Guest
    Found this too, thought I would post:

    Code:
    // This is an example of a UNIX timestamp for the date/time 11-04-2005 09:25.
    double timestamp = 1113211532;
    
    // First make a System.DateTime equivalent to the UNIX Epoch.
    System.DateTime dateTime = new System.DateTime(1970, 1, 1, 0, 0, 0, 0);
    
    // Add the number of seconds in UNIX timestamp to be converted.
    dateTime = dateTime.AddSeconds(timestamp);
    
    // The dateTime now contains the right date/time so to format the string,
    // use the standard formatting methods of the DateTime object.
    string printDate = dateTime.ToShortDateString() +" "+ dateTime.ToShortTimeString();
    
    // Print the date and time
    System.Console.WriteLine(printDate);

  10. #9
    Nightracer's Avatar
    Nightracer is offline Programmer
    Join Date
    Jun 2006
    Posts
    131
    Rep Power
    0
    First time I ran across this time stamp I had no idea what I was looking at. Who in the world would invent a time stamp that is seconds since 1970????

  11. #10
    Join Date
    Aug 2006
    Posts
    11,209
    Blog Entries
    6
    Rep Power
    101
    Well it seems that 'Who' invented it even after 1970s! llooll

Closed Thread
Page 1 of 2 12 LastLast

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Timestamp in C++
    By Hunter100 in forum C and C++
    Replies: 3
    Last Post: 07-04-2010, 07:30 PM
  2. phpbb forum timestamp removal
    By Brok3n in forum PHP Development
    Replies: 1
    Last Post: 07-02-2010, 08:23 AM
  3. timestamp comparison
    By adzeds in forum PHP Development
    Replies: 3
    Last Post: 12-17-2009, 01:41 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts