Database Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsOther TechnologiesDatabase Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
  #1  
Old April 14th, 2004, 09:48 AM
Anonymous Anonymous is offline
Registered User
Codewalkers God 35th Plane (22000 - 22499 posts)
 
Join Date: Apr 2007
Posts: 22,309 Anonymous User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 24
date Select query

i am using the code

$date = time();
and then insert into mysql db as
$sql="INSERT INTO frm_main(name, description, creationDate) VALUES ('$name','$description','$date')";
the creation_date field is int(10)
Now i need to convert this date value from some number say,1081936530 to a valid date in the SELECT query itself before the result is selected

Pls Help

Reply With Quote
  #2  
Old April 14th, 2004, 01:10 PM
nazly nazly is offline
Codewalkers Beginner (1000 - 1499 posts)
 
Join Date: Apr 2007
Location: Colombo,SriLanka
Posts: 1,325 nazly User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 20 m 18 sec
Reputation Power: 3
Send a message via Yahoo to nazly
RE: date Select query

Whats stopping you from setting up creation_date field as DATETIME type?? It will then be easy for Date/Time Calculations + use of Date/Time functions within the SQL statement...

Reply With Quote
  #3  
Old April 18th, 2004, 07:59 AM
CodeKadiya CodeKadiya is offline
Codewalkers Regular (2000 - 2499 posts)
 
Join Date: Apr 2007
Location: Colombo,Sri Lanka
Posts: 2,313 CodeKadiya User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 4
Send a message via Yahoo to CodeKadiya
RE: date Select query

Looks like you are storing the timestamp in a integer field. Why don't you use TIMESTAMP field. if you really want to work with timestamp instead of actual dates?

Anyway, this is the way to convert a timestamp to valid date format inside a sql statement. Just check this example:
php Code:
Original - php Code
  1. <?
  2. $sql = "SELECT FROM_UNIXTIME(1081936530)";
  3.  
  4. $result = mysql_query($sql);
  5. $myDate = mysql_result($result,0);
  6. echo $myDate; // 2004-04-14 15:55:30
  7. ?>


In the same manner, you can grab any part of the date:
php Code:
Original - php Code
  1. <?
  2. $sql = "SELECT FROM_UNIXTIME(1081936530,'%Y')"; // 2004
  3. $sql = "SELECT FROM_UNIXTIME(1081936530,'%d')"; // 14
  4. $sql = "SELECT FROM_UNIXTIME(1081936530,'%m')"; // 04
  5. ?>
Hope that helped!

Reply With Quote
Reply

Viewing: Codewalkers ForumsOther TechnologiesDatabase Help > date Select query


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
Stay green...Green IT