CodeIgniter Forums

Full Version: to_date function not in DB??
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

hi i got this query block on my page.
Quote: <? $date = $inf->Birth;
$mon = $this->db->query("SELECT to_date($date,'MM') from tblstudent where username='".$this->session->userdata('username')."' "); ?>

and i got this error when im running it XD

Quote:<h1>A Database Error Occurred</h1>
<p>Error Number: 1305</p><p>FUNCTION dbmont.to_date does not exist</p><p>SELECT to_date(0000-00-00,'MM') from tblstudent where username='0311435' </p>

El Forum

This isn't really related to CodeIgniter. This is related to which DB you are using. Of course, it would be easier to debug, if you would tell us WHICH RDMS you are using. If you are using MySQL, then no, to_date does not exist.

El Forum

yeah mysql QQ nvrmind.. already made an alternative to split the date.. explode function lols

El Forum

For the record you should use month. For the leading 0 use LPAD.


Returns the month for date, in the range 1 to 12 for January to December, or 0 for dates such as '0000-00-00' or '2008-00-00' that have a zero month part.

mysql> SELECT MONTH('1998-02-03');
        -> 2


Returns the string str, left-padded with the string padstr to a length of len characters. If str is longer than len, the return value is shortened to len characters.

mysql> SELECT LPAD('hi',4,'??');
        -> '??hi'
mysql> SELECT LPAD('hi',1,'??');
        -> 'h'

SELECT LPAD(MONTH('1998-02-03'), 2,'0')

-> 02

El Forum

thats cool.. is there select year and day too??

El Forum