Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Error using Replace Command in VFP 9.0

Status
Not open for further replies.

CPJ1

Programmer
Jun 8, 2017
11
US
I am getting the Operator/operand type mismatch when I try this command:

REPLACE ccoddate WITH "12/14/2020" FOR ccoddate="12/07/2020" ALL

Can someone help me with this. Basically, I am trying to change the date in a column named ccoddate from 12/07/2020 to 12/14/2020. Thanks in advance


 
I use a slightly other syntax for that. Usually I name the target cursor when using REPLACE and ALL is placed right behind the keyword.

Code:
REPLACE [b]ALL[/b] ccoddate WITH ccodedate - 7 FOR ccodedate = "12/07/2020" [b]IN myCursor[/b]

However, as I use another date format your format might as well be a problem too.

JM2C

-Tom
 
This is probably because ccoddate is a Date field rather than a Character field.

If that's right, you need to do this:

Code:
REPLACE ccoddate WITH DATE(2020, 12, 14) FOR ccoddate=DATE(2020, 7, 12)

And, in this case, you don't need the ALL (as for FOR overrides it).

Mike



__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Thanks, Tom.

That did not work. I got an error that myCursor does not exist. Than I got a operand/mismatch when I ran without the myCursor variable. I have a table with a few thousand records. The table has a field called "ccoddate". The date in that field is wrong. It is currently 12/07/2020. It needs to be 12/14/2020. I am using the command prompt to attempt to change the date. Thank you.
 
Thank you. It's working now. My senior programmer is on medical leave for a long time and he did all the VFP programming. It's been awhile since I have to get in there and program. I will need to find a VFP programmer I guess. most of our main programs run JAVA and VFP. Thanks, again.
 
Tom said:
wasn't the a date version with curly brackets... {mm/dd/yyyy}

Yes, there was. But it's no longer recommended, and by default is not supported. It is the old "ambiguous date" format. The problem was a date such as {10/12/20} could have been interpreted as 10 December 2020, or 12 October 2020, or 10 December 1920 or 12 October 1920.

The preferred format is {^2020-10-12}, which is always 12 October 2020. Personally, I prefer the DATE() function, but that's just me.

One other point, Tom. You mentioned putting the ALL immediately after the REPLACE. I do that as well, but it is not at all significant. It makes no difference to the functioning of the command, and in this instance, it has no effect anyway because the FOR takes priority.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Sure, here's what I did:

replace ccoddate with ctod('12/14/2020') with CTOD ('12/14/2020') ALL;

Now I need to delete records with the 12/07/2020 data from an archive table. Should I use the same command but put delete instead? Thanks, again

 
I am sorry I typed the wrong thing.
replace ccoddate with CTOD('12/14/2020') all'
 
Hi,

I am so sorry to come back with the same issue but I am baffled of why the same commands I did on another computer that worked with your help is not working on another computer..

I hope you can help me with this. I am on another computer and using the same VFP command to replace a date in a field with another date. It's not working but worked on the other computer. I have a table with thousands of records and I am simply trying to replace the date in one of the fields. I am using the command window prompt. Here's what I have done:

set defa to f:\database
use news_ccod2014.dbf
REPLACE issuedate with CTOD('12/14/2020') FOR issuedate=CTOD('12/07/2020');

It goes to the EOF but no records are changed. Thanks in advance.
 
I've already suggested a solution - twice.

Code:
REPLACE ccoddate WITH DATE(2020, 12, 14) FOR ccoddate=DATE(2020, 7, 12)

The point is that expressing a data as, for example ('12/14/2020'), is ambiguous, for the reasons I explained in some detail above. Using the DATE() function avoids that issue.

By the way, in your first post, the name of the field was ccodate. Now it seems to be issuedate. Could that be causing a problem?

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
As other computers can have other default date format (BRITISH, FRENCH, GERMAN,..) you better do as Mike suggests. Just a little correction, DATE(y,m,d) will be DATE(2020,12,7) for 7th december 2020 and not DATE(2020,7,12), which is for 12th July.

And thanks for refreshing my memory about the curly brackets format. It's one of the things, where VFP goes another route as all other databases, which usually take a date in some string format. Unfortunately there also are differences and no common format. You have to be very cautious about settings of the different IDEs, it can really change between MDY or DMY, if not even YMD, The DATE() function always needs parameters in the order of YMD, year, month, day. And today is DATE().

So shifting today to next week can be done by using REPLACE field WITH DATE()+7 FOR field = DATE() and shifting last week to today is REPLACE field WITH DATE() FOR field=DATE()-7.

Chriss

PS: You might want to ensure the FOR condition is sufficient, because, in a table as large as you describe, it might as well be you only want to shift some of the records to next week, for example depending on a status field.
 
Thanks everyone for your help. I did get this solved with a combination of your inputs. I cannot remember exactly what I used but it worked and I moved on. Thanks, again!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top