Avatar of Jam9974
Jam9974

asked on 

Date formts in Foxpro SQL

in an SQL statement how to you formate the date to MM/DD/YYYY?
FoxPro

Avatar of undefined
Last Comment
Jam9974
Avatar of Cyril Joudieh
Cyril Joudieh
Flag of Lebanon image

SET DATE TO MDY
SELECT ...
Avatar of Lethal_J
Lethal_J
Flag of United Kingdom of Great Britain and Northern Ireland image

Use the command

SET DATE AMERICAN
Avatar of Pavel Celba
Pavel Celba
Flag of Czechia image

The output date format is based on the FoxPro settings.

You have to issue
SET DATE TO AMERICAN

for your format.

You may also look at
SET CENTURY
SET MARK
SET STRICTDATE
Avatar of Jam9974
Jam9974

ASKER

could I get a full example .

I am basically useing the code below.   And it works fine. I tried to lop off the time using TToD and it errors out my querry also.   so where in that code would I put the above statems.
string MySQL; 
MySQL = "SELECT `prdeds`.`amount`, `prdeds`.`curamount`, `prdeds`.`curemplyr`, `prdeds`.`dedcode`, `hrpersnl`.`p_active`, ";
MySQL+= "`hrpersnl`.`p_fname`,`hrpersnl`.`p_lname`,`hrpersnl`.`p_mi`, ttod(`hrpersnl`.`p_orighire`), `hrpersnl`.`p_ssn`, ";
MySQL+= "`hrpersnl`.`p_termdate`,`prdeds`.`qtdamount`,`prdeds`.`qtdemplyr`, `prdeds`.`ytdamount`,`prdeds`.`ytdemplyr`";
MySQL += ", `prdeds`.`mtdamount`,`prdeds`.`mtdemplyr`, ";
MySQL+= "`hrpersnl`.`p_birth`,`hrpersnl`.`p_hcity`,`hrpersnl`.`p_hstreet1`, `hrpersnl`.`p_hstreet2`, `hrpersnl`.`p_hzip`,";
MySQL+= "`hrpersnl`.`p_hstate`,`hrpersnl`.`p_married`,`hrpersnl`.`p_payfreq` ";
MySQL += "FROM   `hrpersnl` `hrpersnl` left JOIN `prdeds` `prdeds` ON `hrpersnl`.`p_empno`=`prdeds`.`empno` ";

conn.ConnectionString = "Provider=VFPOLEDB.1; Data Source=" + AppSettingInfo.DataFile + ";";
conn.Open();
DataSet DTAbra = new DataSet();
OleDbCommand SQL = new OleDbCommand(MySQL, conn);
OleDbDataAdapter adpter = new OleDbDataAdapter(SQL);
adpter.Fill(DTAbra);
DataTable User401K = DTAbra.Tables[0];
if (User401K.Rows.Count > 0)
{
 my fuction specifics here
}

Open in new window

Avatar of Pavel Celba
Pavel Celba
Flag of Czechia image

What data type is the p_orighire column?

If you need to return given date as a string from SQL command then you have to pass the SET DATE command before the SQL, e.g.

conn.ExecuteNonQuery("EXECSCRIPT([SET DATE TO AMERICAN])")

But American date is a default for VFP OLE DB, so it could be enough to use:

DTOC(ttod(hrpersnl.p_orighire)) AS p_orighire

(single quotes are not necessary in VFP)

You may also remove the TTOD and DTOC functions and format the whole datetime in C#... Why do you need to format it at VFP side?

Avatar of Jam9974
Jam9974

ASKER

its a datetime field.

when do do the DTOC(ttod(hrpersnl.p_orighire)) AS p_orighire
I get the following error :

OleEBExceotion was unhandled
Function argument value, type, or count is invalid.

I am doing a basic copy to a local temp which to do a basic cross tab
ASKER CERTIFIED SOLUTION
Avatar of Pavel Celba
Pavel Celba
Flag of Czechia image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of Pavel Celba
Pavel Celba
Flag of Czechia image

Of course, the code continues:


dbConnection1.Open();
adapter.Fill(table);

// etc.

Open in new window

Avatar of Jam9974
Jam9974

ASKER

took your advice and did it in C# ...

FoxPro
FoxPro

Visual FoxPro (VFP), and its predecessor FoxPro, is a data-centric, object-oriented, procedural, database programming language and IDE from Microsoft last released in 2007 that still has some active use due to its low cost of deployment and fairly rapid development. In 2008, Microsoft released a set of add-ons for VFP's xBase components to allow interoperability with various Microsoft technologies. It allows data processing against its native file-based data tables or database servers such as SQL Server.

11K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo