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
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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.