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

[eluser]KrizzAngel[/eluser]
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

[eluser]n0xie[/eluser]
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

[eluser]KrizzAngel[/eluser]
yeah mysql QQ nvrmind.. already made an alternative to split the date.. explode function lols

El Forum

[eluser]jbreitweiser[/eluser]
For the record you should use month. For the leading 0 use LPAD.

Code:
MONTH(date)

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

LPAD(str,len,padstr)

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

[eluser]KrizzAngel[/eluser]
thats cool.. is there select year and day too??

El Forum