Branman Posted February 19, 2008 Share Posted February 19, 2008 Hello everyone, My name is Brandon and I'm fairly new to php. I just had some questions... In the database I am using the premium subscription END date is stored as a unix time stamp. however when I go to see it I get a date back from 1969..: its a simple date convert script Quote Link to comment Share on other sites More sharing options...
obsidian Posted February 19, 2008 Share Posted February 19, 2008 Any code? My guess is that if you're not using a DATETIME in your database, you may be calling strtotime() or another date function on a value that is invalid. Quote Link to comment Share on other sites More sharing options...
craygo Posted February 19, 2008 Share Posted February 19, 2008 you can do it 2 ways, using mysql or using php to convert the timestamp mysql $sql = "SELECT FROM_UNIXTIME(`fieldname`,'%Y %D %M %h:%i:%s %x') AS newdate FROM tablename"; Now newdate will be your formatted date php <?php $sql = "SELECT * FROM tablename"; $res = mysql_query($sql) or die(mysql_error()); while($r = mysql_fetch_array($res)){ $newdate = date("Y-m-d G:i:s", $r['timestamp']); } ?> Ray Quote Link to comment Share on other sites More sharing options...
Branman Posted February 20, 2008 Author Share Posted February 20, 2008 Well, as you can tell I am extremely nooblety at this. Here is what I have: Current Code: [code=php:0]$sql = mysql_query("SELECT * FROM ibf_subscription_trans WHERE id=". $_COOKIE['member_id']); while ($r = mysql_fetch_array($sql)) { $newdate = date("Y-m-d G:i:s", $r['subtrans_end_date']); echo "$newdate"; } Timestamp information: Table Name: ibf_subscription_trans Field Name: subtrans_end_date All I want to display is - the end date =/ The code above did not work. Quote Link to comment Share on other sites More sharing options...
obsidian Posted February 20, 2008 Share Posted February 20, 2008 What data type is the column subtrans_end_date? I'm guessing DATE by the name, and if so, you simply need to translate your result to a timestamp to parse: <?php $newdate = date('Y-m-d G:i:s', strtotime($r['subtrans_end_date'])); echo $newdate; ?> Quote Link to comment Share on other sites More sharing options...
Branman Posted February 21, 2008 Author Share Posted February 21, 2008 Still comes out to 1969 =/ Quote Link to comment Share on other sites More sharing options...
revraz Posted February 21, 2008 Share Posted February 21, 2008 Post the actual timestamp value that you are using. Quote Link to comment Share on other sites More sharing options...
Branman Posted February 21, 2008 Author Share Posted February 21, 2008 1202336734 <- That's one of them. Quote Link to comment Share on other sites More sharing options...
revraz Posted February 21, 2008 Share Posted February 21, 2008 This works fine for me <?php $newdate = date("Y-m-d G:i:s", 1202336734); echo "$newdate"; ?> echo $r['subtrans_end_date']; and make sure its the same number. Quote Link to comment Share on other sites More sharing options...
obsidian Posted February 22, 2008 Share Posted February 22, 2008 1202336734 <- That's one of them. If you are storing them in that format (UNIX timestamp), you can just remove the strtotime() call within the date function. I was assuming by your column name that you were using the MySQL DATETIME data type rather than storing it as an integer. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.