Notices
Computer & Technology Related Post here for help and discussion of computing and related technology. Internet, TVs, phones, consoles, computers, tablets and any other gadgets.

MySQL help please

Thread Tools
 
Search this Thread
 
Old 04 April 2002, 07:23 AM
  #1  
Figment
Scooby Regular
Thread Starter
 
Figment's Avatar
 
Join Date: Jul 2001
Location: deep inside your imagination
Posts: 24,057
Likes: 0
Received 0 Likes on 0 Posts
Question

How do I convert dateline fields in a MySQL database to 'real' dates?

TIA
Old 04 April 2002, 08:20 AM
  #2  
jharris
Scooby Regular
 
jharris's Avatar
 
Join Date: Mar 2002
Location: Bristol
Posts: 61
Likes: 0
Received 0 Likes on 0 Posts
Post

Do you mean dateTIME fields? If so I don't think you'll really need to do any conversion, just a little formatting as they tend to take the format of YYYY-MM-DD HH:MM:SS... Are you trying to do this conversion directly in MySQL or are you dragging the data out into an application and converting it there? Or have I missed something?

cheers

Jamie...
Old 04 April 2002, 12:04 PM
  #3  
Figment
Scooby Regular
Thread Starter
 
Figment's Avatar
 
Join Date: Jul 2001
Location: deep inside your imagination
Posts: 24,057
Likes: 0
Received 0 Likes on 0 Posts
Post

As an example, the table has a field called dateline, type int(10) unsigned, and a sample record contains the value 1013120482 in this field.

I am trying to (manually) work out what date this represents, so that I can purge the table of all records older than nnn days
Old 04 April 2002, 12:08 PM
  #4  
Figment
Scooby Regular
Thread Starter
 
Figment's Avatar
 
Join Date: Jul 2001
Location: deep inside your imagination
Posts: 24,057
Likes: 0
Received 0 Likes on 0 Posts
Post

The value 1017920994 is today, if that helps any
Old 04 April 2002, 12:19 PM
  #5  
stevencotton
Scooby Regular
 
stevencotton's Avatar
 
Join Date: Jan 2001
Location: behind twin turbos
Posts: 2,710
Likes: 0
Received 1 Like on 1 Post
Post

[steven@moya steven]$ perl -e 'print scalar localtime(1013120482), "\n";'
Thu Feb 7 22:21:22 2002

It's in UNIX epoch time format, number of seconds since Jan 1st 1970.

Steve.
Old 04 April 2002, 04:37 PM
  #6  
Figment
Scooby Regular
Thread Starter
 
Figment's Avatar
 
Join Date: Jul 2001
Location: deep inside your imagination
Posts: 24,057
Likes: 0
Received 0 Likes on 0 Posts
Post

Thanks Steve - now all I need to find is a convertor to change one to the other.
Old 04 April 2002, 05:16 PM
  #7  
legacyPete
Scooby Regular
 
legacyPete's Avatar
 
Join Date: Dec 2001
Posts: 202
Likes: 0
Received 0 Likes on 0 Posts
Post

Taking into account previous posts you could give this a try (back up before trying!!)

Create an extra column, in this case called newcolumn of type datetime

Then run this to transfer the dates accross:

update yourtable set `newcolumn` = date_add("1970-01-01", interval `olddatecolumn` second);

[Edited by legacyPete - 4/4/2002 6:19:39 PM]

[Edited by legacyPete - 4/4/2002 6:40:04 PM]
Old 05 April 2002, 07:29 AM
  #8  
Figment
Scooby Regular
Thread Starter
 
Figment's Avatar
 
Join Date: Jul 2001
Location: deep inside your imagination
Posts: 24,057
Likes: 0
Received 0 Likes on 0 Posts
Post

Thanks Legacypete, that is absolutely first class and works a treat
Old 05 April 2002, 12:06 PM
  #9  
legacyPete
Scooby Regular
 
legacyPete's Avatar
 
Join Date: Dec 2001
Posts: 202
Likes: 0
Received 0 Likes on 0 Posts
Post

...we aim to please
Related Topics
Thread
Thread Starter
Forum
Replies
Last Post
Wurzel
Computer & Technology Related
2
07 May 2007 05:45 PM
g3m xr
Southern (England)
6
13 September 2006 11:38 PM
GaryK
Computer & Technology Related
2
08 December 2004 11:04 AM
SiDHEaD
Computer & Technology Related
7
03 November 2003 10:17 AM



Quick Reply: MySQL help please



All times are GMT +1. The time now is 10:43 PM.