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!

Replacing Date Fields

Status
Not open for further replies.
Jan 21, 2002
112
GB
Trying to replace a date field using following 2 examples and I am getting "function argument value,type or account is invalid". I have SET DATE BRITISH AND SET CENTURY ON.

replace it_dteinv with DTOC(05/28/2010) FOR IT_DOC="DOC11320"
replace it_dteinv with dtoc(22/06/2010) FOR IT_DOC="DOC11249"

Any advice please?
 
Code:
replace it_dteinv with "05/28/2010" FOR IT_DOC="DOC11320"
replace it_dteinv with "22/06/2010" FOR IT_DOC="DOC11249"

If you know the string value beforehand why use DTOC()?

The other way is to use DATE() function.
Code:
replace it_dteinv with DTOC(DATE(2010, 5, 28)) ;
        FOR IT_DOC="DOC11320"

and the BEST thing is to use DATE field to keep dates there.

Borislav Borissov
VFP9 SP2, SQL Server 2000,2005 & 2008.
 
Since you are attempting to use the DTOC() function we must assume that the field it_dteinv is a Character field type.

If not, then you are using the wrong function.

If it is a Character type field, then the above suggestions should work well for you.

However, you state "Trying to replace a date field" which implies that the field is not a Character type field, but instead a Date type field.

If the field is indeed a Date type, then the above will not work. You would need to use something like:

Code:
REPLACE it_dteinv with CTOD('05/28/2010');
   FOR IT_DOC="DOC11320"

Good Luck,
JRB-Bldr

 
Jackmetickler,

You've been given a lot of good advice. Just to add my small contribution:

You say you have SET DATE BRITISH. In that case, neither CTOD('05/28/2010') nor DTOC(05/28/2010) will give a valid result. You would have to reverse the month and day.

In general, it's better to use either the "unambiguous" date format:

Code:
{^2010-05-28}

or the DATE() function:

Code:
DATE(2010, 5, 28)

as these are independent of SET DATE or other formatting settings.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro tips, advice, training, consultancy
Custom software for your business
 
If it_dteinv is a date field, you can't store a string into it. DTOC() does make a string from a date: (transform) D(ate) TO C(har).

You do use the DATE() function as suggested or replace it_dteinv with Ctod("05/28/2010") for example. 05/28/2010 is a date string and you need the inverse function creating a date from that string. But it's better not to use that syntax, as it fails if the date settings differ, you should use setting independant code like {^YYYY-MM-DD} or DATE(YYYY,MM,DD)

Bye, Olaf.
 
Gentlemen

Many thanks for all great advice. I am off-site today so I cannot test at moment but I will get back to you ASAP when I have chance. I am sure you have sorted problem.

Once again your assistance greatly appreciated.

Regards
Jack
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top