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

[5.3] Where year type issue #16737

Closed
vinkla opened this issue Dec 10, 2016 · 5 comments
Closed

[5.3] Where year type issue #16737

vinkla opened this issue Dec 10, 2016 · 5 comments

Comments

@vinkla
Copy link
Contributor

vinkla commented Dec 10, 2016

  • Laravel Version: 5.3.26
  • PHP Version: 7.1
  • Database Driver & Version: MySQL 14.14 Distrib 5.7.16

Description:

I've database table of orders. I fetch the orders with whereYear. If the year argument is a integer it wont find any orders but if I typecast the year to a string it works.

This might be something on my end but I found it odd so I thought it was best to report it.

Also, this worked fine on PHP 7.0 without any issues.

Edit: I double checked the documentation and the examples are using strings. Maybe we should typecast all integers to strings for whereYear, whereDay and whereMonth? Or maybe force developers to pass strings?

Steps To Reproduce:

This wont work since the year is an integer.

Order::whereYear('created_at', Carbon::now()->year)->get();

This will work since the year is a string.

Order::whereYear('created_at', (string) Carbon::now()->year)->get();
@rojtjo
Copy link
Contributor

rojtjo commented Dec 11, 2016

I was unable to reproduce this issue.
Do you see any difference between the executed queries besides the datatype of the year?

@vinkla
Copy link
Contributor Author

vinkla commented Dec 11, 2016

None that I can find at least. Both cases prints the same SQL query.

select * from "orders" where strftime('%Y', "created_at") = ? and "orders"."deleted_at" is null

@billmn
Copy link
Contributor

billmn commented Dec 21, 2016

All works fine for me ... I have tried to use string and integer but the result is the same.

  • Laravel 5.3.28
  • PHP 7.1
  • MySQL 5.7.15

@themsaid
Copy link
Member

Can't generate this either, @vinkla did you manage to get around it by any means?

@vinkla
Copy link
Contributor Author

vinkla commented Dec 23, 2016

@themsaid no, it only works if I typecast the integers to strings. Maybe it is something on my machine and setup. Closing this for now. Thanks for getting back.

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

No branches or pull requests

4 participants