Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to use FROM_UNIXTIME function #69

Closed
selabie68 opened this issue Dec 2, 2015 · 4 comments
Closed

Unable to use FROM_UNIXTIME function #69

selabie68 opened this issue Dec 2, 2015 · 4 comments
Assignees
Labels

Comments

@selabie68
Copy link

Writing code like so:

$builder = new MySqlBuilder();

$query = $builder->select()
            ->setTable('invoices');

$columns['Invoice Number'] = 'invoice_number'; //Always Display
$query->setColumns($columns);
$query->setFunctionAsColumn('FROM_UNIXTIME', array('invoices.invoice_date', '%d/%m/%Y'), 'Date Entered');
$builder->write($query);

And it is returning MySQL that is invalid:

SELECT `invoices`.`invoice_number` AS `Invoice Number`, ``.`FROM_UNIXTIME(invoices.invoice_date, %d/%m/%Y)` AS `Date Entered` FROM `invoices`
@selabie68 selabie68 changed the title Unable to use UNIX_TIMESTAMP function Unable to use FROM_UNIXTIME function Dec 2, 2015
@nilportugues nilportugues self-assigned this Dec 2, 2015
@nilportugues
Copy link
Owner

@anarcist69 it is indeed a bug, as the GenericBuilder is outputting the expected query.

I'll look into it today. It shouldn't be too hard to fix.

Thanks for reporting, I'll keep you posted

@nilportugues
Copy link
Owner

Fixed it. 3dca30b

Use release 1.2.1 👍

@selabie68
Copy link
Author

Thanks, almost got it. Looks like it still isn't outputting quite right.

MySQL requires formatting like this:

FROM_UNIXTIME(invoices.invoice_date, "%d/%m/%Y")

output is like this (Note the spaces after % signs and no quotation marks surrounding the second argument):

FROM_UNIXTIME(invoices.invoice_date, % d /% m /% Y)

Thanks for responding so fast.

EDIT:

Sorry shouldn't have responded so fast.

Changed my code to include the quotation marks and all is fine in the world again.

$query->setFunctionAsColumn('FROM_UNIXTIME', array('invoices.invoice_date', '"%d/%m/%Y"'), 'Date Entered');

@changetip, send coffee to @nilopc

@changetip
Copy link

Hi @nilopc, @anarcist69 sent you a tip worth 1 coffee (4,060 bits/$1.50), and I'm here to deliver it ➔ collect your tip.

Learn more about ChangeTip

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants