I need to set a date field to be way into the future.
So if the field is not 0000-00-00, I was to set the first four "0000" to be "2030".....
How do I do that?
How do I update forst 4 charcs, where first four <> 0000?
Moderator: General Moderators
-
simonmlewis
- DevNet Master
- Posts: 4435
- Joined: Wed Oct 08, 2008 3:39 pm
- Location: United Kingdom
- Contact:
How do I update forst 4 charcs, where first four <> 0000?
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
All the best from the United Kingdom.
-
simonmlewis
- DevNet Master
- Posts: 4435
- Joined: Wed Oct 08, 2008 3:39 pm
- Location: United Kingdom
- Contact:
Re: How do I update forst 4 charcs, where first four <> 0000
Code: Select all
UPDATE products SET datefield= '2030-01-01' WHERE LEFT(datefield, 4) <> '0000' Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
All the best from the United Kingdom.
Re: How do I update forst 4 charcs, where first four <> 0000
It's trivial to test. Have you tried?simonmlewis wrote:Does this look correct??Code: Select all
UPDATE products SET datefield= '2030-01-01' WHERE LEFT(datefield, 4) <> '0000'
Re: How do I update forst 4 charcs, where first four <> 0000
Rather than doing a string compare, I'd recommend using the YEAR function
-
simonmlewis
- DevNet Master
- Posts: 4435
- Joined: Wed Oct 08, 2008 3:39 pm
- Location: United Kingdom
- Contact:
Re: How do I update forst 4 charcs, where first four <> 0000
I have. It seemed to work. Just wondered if it was the appropriate method.
Not seem that function before, but I get technically why that would be better To adjust the year on a date field, rather than the entire string.
Not seem that function before, but I get technically why that would be better To adjust the year on a date field, rather than the entire string.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
All the best from the United Kingdom.