Jump to content

A few Extremely Simple Questions


Branman

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/91878-a-few-extremely-simple-questions/
Share on other sites

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

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.

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;
?>

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.