Lost Password?

Go Back   CodeCall Programming Forum > Software Development > C# Programming

C# Programming C# (pronounced C-sharp) is a new object oriented language from Microsoft and is derived from C and C++. It also borrows a lot of concepts from Java too including garbage collection.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 09-26-2006, 12:50 PM
dirkfirst dirkfirst is offline
Programming Professional
 
Join Date: May 2006
Posts: 338
Rep Power: 11
dirkfirst is on a distinguished road
Default 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#.
__________________
DirkFirst
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
  #2 (permalink)  
Old 09-26-2006, 07:48 PM
brackett brackett is offline
Programmer
 
Join Date: May 2006
Posts: 193
Rep Power: 10
brackett is on a distinguished road
Default

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()
}
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 09-27-2006, 08:57 AM
Saint Saint is offline
Learning Programmer
 
Join Date: Aug 2006
Posts: 63
Rep Power: 8
Saint is on a distinguished road
Default

As for sorting you should be able to sort by that number in SQL.

ORDER BY field ASC
__________________
Hi >> Saint
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 09-29-2006, 05:09 PM
Jordan's Avatar   
Jordan Jordan is offline
Administrator
 
Join Date: Nov 2005
Location: Hendersonville, NC
Age: 26
Posts: 6,004
Last Blog:
SAP, ERP and EDI
Rep Power: 20
Jordan has much to be proud ofJordan has much to be proud ofJordan has much to be proud ofJordan has much to be proud ofJordan has much to be proud ofJordan has much to be proud ofJordan has much to be proud ofJordan has much to be proud ofJordan has much to be proud of
Send a message via ICQ to Jordan Send a message via AIM to Jordan Send a message via MSN to Jordan
Default

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.
__________________
CodeCall Blog | CodeCall Wiki | Shareware Site | Linux Forum | Write a Blog
Don't hesitate to ask any questions that you have! Check out our ASCII Calculator!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 10-02-2006, 09:08 AM
smith smith is offline
Programmer
 
Join Date: Jun 2006
Posts: 108
Rep Power: 9
smith is on a distinguished road
Default

Here is a converter - http://www.onlineconversion.com/unix_time.htm
__________________
Code:
for (int i;;) {
   cout << "Smith";
}
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
  #6 (permalink)  
Old 10-02-2006, 11:46 AM
TcM's Avatar   
TcM TcM is offline
Moderator
 
Join Date: Aug 2006
Location: In a technologic world :p
Posts: 7,360
Rep Power: 67
TcM has much to be proud ofTcM has much to be proud ofTcM has much to be proud ofTcM has much to be proud ofTcM has much to be proud ofTcM has much to be proud ofTcM has much to be proud ofTcM has much to be proud of
Default

So acording to that converter that timestrap is:-
Tue, 27 Sep 2005 16:00:26 UTC
??
hmm it looks like an encrypted string! cool!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 10-03-2006, 06:05 PM
dirkfirst dirkfirst is offline
Programming Professional
 
Join Date: May 2006
Posts: 338
Rep Power: 11
dirkfirst is on a distinguished road
Default

Thanks, that is exactly what that number is. Your C# code worked great brackett, thanks.
__________________
DirkFirst
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 11-29-2006, 10:57 AM
NeedHelp NeedHelp is offline
Programming God
 
Join Date: May 2006
Posts: 527
Rep Power: 12
NeedHelp is on a distinguished road
Default

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);
__________________
I Need Help
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #9 (permalink)  
Old 12-04-2006, 06:51 PM
Nightracer's Avatar   
Nightracer Nightracer is offline
Programmer
 
Join Date: Jun 2006
Posts: 130
Rep Power: 9
Nightracer is on a distinguished road
Default

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????
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #10 (permalink)  
Old 12-05-2006, 09:32 AM
TcM's Avatar   
TcM TcM is offline
Moderator
 
Join Date: Aug 2006
Location: In a technologic world :p
Posts: 7,360
Rep Power: 67
TcM has much to be proud ofTcM has much to be proud ofTcM has much to be proud ofTcM has much to be proud ofTcM has much to be proud ofTcM has much to be proud ofTcM has much to be proud ofTcM has much to be proud of
Default

Well it seems that 'Who' invented it even after 1970s! llooll
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT -5. The time now is 11:17 PM.

Contest Stats

Xav ........ 162.68
Sacback ........ 120.05
alearb8 ........ 120.05
tfusion ........ 120
amr2107 ........ 120
d3s!gn ........ 120
Qoolman21 ........ 120
Pillager ........ 108
satrian ........ 100
neerlin ........ 100

Contest Rules

CodeCall Goal

Goal: 100,000 Posts
Complete: 68%

Ads