Communication is key. Once you've started working on something and it looks like it might not work out or take a lot longer than expected, discuss this with your manager and find out how they would like you to proceed.
My approach is to make my case for why I should keep working on a particular thing (especially if I feel strongly about it and/or confident I can make it work given enough time), but ultimately respecting their decision. I find this works well.
The cases where I've spent weeks/months on something are either where I was in charge of the project (during grad school, and later as an indie developer), or as an employee where my manager considered the task to be of sufficient importance to the business to continue down the path, even if it means spending more time or trying a few different approaches until I find one that works. This is especially the case with research-oriented projects where you don't know where a path is going to lead until you go down it.
My approach is to make my case for why I should keep working on a particular thing (especially if I feel strongly about it and/or confident I can make it work given enough time), but ultimately respecting their decision. I find this works well.
The cases where I've spent weeks/months on something are either where I was in charge of the project (during grad school, and later as an indie developer), or as an employee where my manager considered the task to be of sufficient importance to the business to continue down the path, even if it means spending more time or trying a few different approaches until I find one that works. This is especially the case with research-oriented projects where you don't know where a path is going to lead until you go down it.