Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

stoopid date stamp question

Status
Not open for further replies.

bigbird3156

Programmer
Feb 20, 2001
183
AU
Hi...

I can't get my head around the date stamp format thingy...

how do I code the following so that I only get the date displayed (ie no time) in a d/m/Y format???

Code:
<?php echo $row_del_rec['date_added']; ?>

[wiggle]The Bird from Down Under- Bigbird 3156
Programmer?? - I thought the option was pretender not programmer!![jester]
 
Hi

Supposing that $row_del_rec['date_added'] contains a timestamp :
Code:
<?php echo [url=http://php.net/date/]date[/url]('d/m/Y',$row_del_rec['date_added']); ?>
Otherwise tell us what $row_del_rec['date_added'] contains.

Feherke.
 
assuming you mean by timestamp a unix timestamp, Feherke's solution is spot on.

however, as Feherke intimates, the word timestamp covers a multitude of sins! if the above does not work for you try converting the timestamp into a unix timestamp with strtotime() before using it in the date() function.
 
Hi,
thanks for that... I did need the strtotime() thingy as well as what Feherke added... without it all my dates were displayed as 1/1/1970...

[wiggle]The Bird from Down Under- Bigbird 3156
Programmer?? - I thought the option was pretender not programmer!![jester]
 
Hi

Bigbird said:
without it all my dates were displayed as 1/1/1970...
That is the date of the Unix timestamp 0. If you pass the date as string like '2009-05-15' to a function which expects timestamp, it will be convert it to integer first. And '2009-05-15', or other similar string, converted to integer is 0. So if you see a date formatted to '1/1/1970', check if the format function's parameter can be correctly converted to integer.

Feherke.
 
Also note that if the value is coming from the database, you can format it in the query itself. I just fear that you have a date that is formatted into a string, reformatted into a date and formatted again into a string.

Would it be possible to show us more of the code, one that will show us where the value comes from?

[small]Do something about world cancer today: Comprehensive cancer control information at PACT[/small]
 
sorry... I'm not really sure what you are asking for...

the best I could find is this??? - dunno if it is what you are after... I'm a bit of a noob and trying to learn as I go...

Code:
  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    ...

    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    ...
  }
  return $theValue;

[wiggle]The Bird from Down Under- Bigbird 3156
Programmer?? - I thought the option was pretender not programmer!![jester]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top