Jump to content

Welcome to Geeks to Go - Register now for FREE

Geeks To Go is a helpful hub, where thousands of volunteer geeks quickly serve friendly answers and support. Check out the forums and get free advice from the experts. Register now to gain access to all of our features, it's FREE and only takes one minute. Once registered and logged in, you will be able to create topics, post replies to existing threads, give reputation to your fellow members, get your own private messenger, post status updates, manage your profile and so much more.

Create Account How it Works
Photo

MySQL convert int to timedate?


  • Please log in to reply

#1
admin

admin

    Founder Geek

  • Administrator
  • 24,504 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
  • Administrator
  • 24,504 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
  • Administrator
  • 24,504 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