Jump to content

Welcome to Geeks to Go - Register now for FREE

Need help with your computer or device? Want to learn new tech skills? You're in the right place!
Geeks to Go is a friendly community of tech experts who can solve any problem you have. Just create a free account and post your question. Our volunteers will reply quickly and guide you through the steps. Don't let tech troubles stop you. Join Geeks to Go now and get the support you need!

How it Works Create Account
Photo

MySQL convert int to timedate?


  • Please log in to reply

#1
admin

admin

    Founder Geek

  • Community Leader
  • 24,639 posts
I have an SQL table in an old application that stored the date and time as an integer - int(11). I want to use it in a new ap that uses timedate. How do I convert the data from int to timedate?
  • 0

Advertisements


#2
stettybet0

stettybet0

    Trusted Tech

  • Technician
  • 2,579 posts
hi admin, and welcome to G2G! :whistling:

As for your problem, why not just define the date and time as "datetime" in the first place instead of "int"?

-stettybet0
  • 0

#3
admin

admin

    Founder Geek

  • Topic Starter
  • Community Leader
  • 24,639 posts
I have 1,000+ rows sorted using a date field. If I change them all to a default they won't be in any kind of order. I'd also prefer to keep the date field correct.
  • 0

#4
Michael

Michael

    Retired Staff

  • Retired Staff
  • 1,869 posts
I am presuming the integer is a time stamp, is which case you can do

$date = date("Y-m-d",$timestamp);

That will produce something like 1989-12-23 depending on the $timestamp

EDIT: http://au3.php.net/m...nction.date.php

Edited by Michael, 20 April 2007 - 12:37 AM.

  • 0

#5
admin

admin

    Founder Geek

  • Topic Starter
  • Community Leader
  • 24,639 posts
I want to change the actual data in the table, not parse it with PHP. Looks like FROM_UNIXTIME will work:
http://dev.mysql.com...n_from-unixtime
  • 0

#6
Michael

Michael

    Retired Staff

  • Retired Staff
  • 1,869 posts
If your only dealing with about 1000 rows it would be easy to get the date, change it, then update it. But useing pure SQL would be easy enough too.


I personally doing the exact opposite, and changing all to a time stamp (unix time) because it is more flexible, I can easily change it for time zone differences or print it in a number of different formats.
  • 0






Similar Topics

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

As Featured On:

Microsoft Yahoo BBC MSN PC Magazine Washington Post HP