PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
 
Loading
It is currently Sun Apr 23, 2017 2:41 pm

All times are UTC - 5 hours




Post new topic Reply to topic  [ 5 posts ] 
Author Message
PostPosted: Tue Aug 30, 2016 3:36 am 
Offline
DevNet Master

Joined: Wed Oct 08, 2008 3:39 pm
Posts: 4145
Location: United Kingdom
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?

_________________
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.


Top
 Profile  
 
PostPosted: Tue Aug 30, 2016 3:41 am 
Offline
DevNet Master

Joined: Wed Oct 08, 2008 3:39 pm
Posts: 4145
Location: United Kingdom
Syntax: [ Download ] [ Hide ]
UPDATE products SET datefield= '2030-01-01' WHERE LEFT(datefield, 4) <> '0000'

Does this look correct??

_________________
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.


Top
 Profile  
 
PostPosted: Tue Aug 30, 2016 6:41 am 
Offline
Moderator
User avatar

Joined: Tue Nov 09, 2010 3:39 pm
Posts: 6219
Location: Montreal, Canada
simonmlewis wrote:
Syntax: [ Download ] [ Hide ]
UPDATE products SET datefield= '2030-01-01' WHERE LEFT(datefield, 4) <> '0000'

Does this look correct??

It's trivial to test. Have you tried?

_________________
Supported PHP versions No longer supported versions


Top
 Profile  
 
PostPosted: Tue Aug 30, 2016 6:51 am 
Offline
Moderator
User avatar

Joined: Tue Nov 09, 2010 3:39 pm
Posts: 6219
Location: Montreal, Canada
Rather than doing a string compare, I'd recommend using the YEAR function

_________________
Supported PHP versions No longer supported versions


Top
 Profile  
 
PostPosted: Tue Aug 30, 2016 7:18 am 
Offline
DevNet Master

Joined: Wed Oct 08, 2008 3:39 pm
Posts: 4145
Location: United Kingdom
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.

_________________
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: Exabot [Bot] and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group