Welcome Guest, Not a member yet? Register   Sign In
Date convert from SQL
#1

[eluser]Chilion[/eluser]
Hi!

I have a date from a sql DATE field.

Then I want to turn that into my preffered format. I use the mdate function now in this way:
Code:
<?php
      $datestring = '%d-%m-%Y';
      echo mdate($datestring, $statistic->creationDate);
     ?>

Then I get an error:
Quote:Fatal error: Call to undefined function mdate() in C:\USBWebserver\root\Dweper\frameworkSysteemCodeSecure\core\Loader.php(829) : eval()'d code on line 24

$statistic->creationDate is filled as: 2012-01-04

Hope u can help!
#2

[eluser]PhilTem[/eluser]
There's no native PHP mdate function but it's a CI helper function. So you should ensure, that you loaded the date-helper prior to calling the method.

Secondly, I think you're not using the write markup. From the user's guide
Quote:
Code:
$datestring = "Year: %Y Month: %m Day: %d - %h:%i %a";
$time = time();

echo mdate($datestring, $time);

In this case, $time is something like 123456789. And that's not matching your format Wink
#3

[eluser]Chilion[/eluser]
What should I use to do it the way I want it then?
#4

[eluser]Unknown[/eluser]
You can use native PHP code

Code:
<?php
      $datestring = 'd-m-Y';
      echo date($datestring, strtotime($statistic->creationDate));
     ?>

http://php.net/manual/en/function.date.php
#5

[eluser]Ajaxboy[/eluser]
Code:
<?php
$time = strtotime($statistic->creationDate);
echo date("d-m-Y", $time );
?>
#6

[eluser]CroNiX[/eluser]
I prefer to do the date conversion in the actual query using DATE_FORMAT() so it returns the format I want from the getgo.
http://www.w3schools.com/sql/func_date_format.asp




Theme © iAndrew 2016 - Forum software by © MyBB