Jump to content

[SOLVED] Date Funtion


phpretard

Recommended Posts

I am trying to display the date like - 08-01-2009 by calling a function with a var.

 

I know the code below is wrong but it's what I'm working with.

 

 


<?php

function myDate($startdate){

    echo "The date is ". $startdate;

	$startdate="2009-08-01 07:27:40";
	$predate=explode(' ', $startdate);
	$splitdate=explode('-', $predate[0]);
	$redeemDate="$splitdate[1]-$splitdate[2]-$splitdate[0]";
	$new_date="$startdate";
	    
}

myDate($new_date);

?>

 

Thank you!

Link to comment
https://forums.phpfreaks.com/topic/168389-solved-date-funtion/
Share on other sites

Or, if you're timestamp is coming from a database, you can do it directly in the query: http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html#function_date-format

 

TIGHT!!!

 

So if I have a date in the DB as: 2009-08-01 07:27:40

 

I am not sure how to use it like this...

 

GET_FORMAT(DATE,'USA') '%m.%d.%Y'

 

select date from table ???

 

Link to comment
https://forums.phpfreaks.com/topic/168389-solved-date-funtion/#findComment-888251
Share on other sites

Got it!

 


function myDate($table){

connect();
$the_date=mysql_query("select date from $table");	
while ($date=mysql_fetch_assoc($the_date))
{
$startdate=$date['date'];
}mysql_free_result($the_date);


	$predate=explode(' ', $startdate);
	$splitdate=explode('-', $predate[0]);
	$readDate="$splitdate[1]-$splitdate[2]-$splitdate[0]";
	$new_date="$readDate";

	echo $new_date; 
	    
}

myDate("categories");

?>

Link to comment
https://forums.phpfreaks.com/topic/168389-solved-date-funtion/#findComment-888255
Share on other sites

Here it is used in a different function:

 

 

function cat_tr(){

connect();

$get_cat = mysql_query("select * from categories order by cat_name");
while ($cat=mysql_fetch_assoc($get_cat))
{
echo"
<tr>
	<td>".$cat['cat_name']."</td>
	<td><a href=\"javascript:void(0)\"><img border=\"0\" alt=\"Edit ".$cat['cat_name']."\" src=\"images/b_edit.png\" width=\"16\" height=\"16\"></a></td>
	<td><a href=\"javascript:void(0)\"><img border=\"0\" alt=\"Delete ".$cat['cat_name']."\" src=\"images/b_drop.png\" width=\"16\" height=\"16\"></a></td>
	<td>";myDate("categories");echo"</td>
</tr>
";
}
mysql_free_result($get_cat);
}

Link to comment
https://forums.phpfreaks.com/topic/168389-solved-date-funtion/#findComment-888256
Share on other sites

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.