Welcome Guest, Not a member yet? Register   Sign In
to_date function not in DB??
#1

[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>
#2

[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.
#3

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

[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
#5

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

[eluser]n0xie[/eluser]
http://dev.mysql.com/doc/refman/5.1/en/d...tions.html




Theme © iAndrew 2016 - Forum software by © MyBB