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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VFP TO EXCEL AUTOMATION

Status
Not open for further replies.

JINESH GANDHI

IS-IT--Management
May 8, 2022
12
0
0
IN
Hello

I want to know how to convert Date to Text Format using vfp programming.

Please help me very urgent
 
I am guessing you want a string version of a date variable?

Code:
m.MyDateString = dtoc(m.date)

You might use it like this
Code:
** NOW NEED TO OPEN THE SHEET AND PUT IN THE EXTRA COLUMNS
OEXCEL = CREATEOBJECT("Excel.Application")
* make excel visible during development
OEXCEL.VISIBLE = .F.
OEXCEL.WORKBOOKS.ADD

OEXCEL.CELLS.FONT.SIZE = 8
OEXCEL.CELLS(3,3).VALUE = "Date : "+DTOC(DATE())

I sometimes like the date in long form using a UDF DTOL()

Code:
FUNCTION DTOL
	LPARAMETERS m.DATE
	LOCAL m.STRING
	IF !EMPTY(m.DATE)
		m.STRING = LTRIM(LEFT(DTOC(m.DATE),2))+" "
		m.STRING = m.STRING + CMONTH(m.DATE)+" "
		m.STRING = m.STRING + STR(YEAR(m.DATE),4,0)
	ELSE
		m.STRING = ""
	ENDIF
	RETURN(m.STRING)

Regards

Griff
Keep [Smile]ing

There are 10 kinds of people in the world, those who understand binary and those who don't.

I'm trying to cut down on the use of shrieks (exclamation marks), I'm told they are !good for you.

There is no place like G28 X0 Y0 Z0
 
Thank You dear,

This I have already done but still the column shows date format.

I want to input date as text in "DD-MMM-YYYY" format (e.g. 07-Jul-2022) and I mean the data must be input as text
How it is possible?
 
Are you collecting the data from a field on a form?
If so, you can simply set the date format that VFP uses to that in your environment.


Best Regards,
Scott
MSc ISM, MIET, MASHRAE, CDCAP, CDCP, CDCS, CDCE, CTDC, CTIA, ATS

"I try to be nice, but sometimes my mouth doesn't cooperate.
 
Yes Exactly I am collecting data my sample code as follows:

create cursor temp (c1 c(11))
select temp
append blank
repl c1 with substr(dtoc(date()),1,2)+"-"+substr(cmonth(date(),1,3)+"-"+alltrim(str(year(date())))
** e.g. date 07/07/22 to 07-Jul-2022
** now I am trying to paste these data to excel column
** excel colum shows "07-Jul-22" when i press f2 it shows 7/7/2022
** I want same as in text format after pasting data to excel file.

Is there any solution Sir ?
 
Quick answer is For Excl :
repl c1 with "'"+substr(dtoc(date()),1,2)+"-"+substr(cmonth(date(),1,3)+"-"+alltrim(str(year(date())))

user the "'" as first letter for Excl column.
(use single quote)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top