FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Date Convertion function doubt
Posts: 1335
Joined: Fri Jun 13, 2008 11:04 AM
Date Convertion function doubt
Posted: Thu Jan 07, 2010 09:57 AM

Hi,

Is there a function available to convert date into the Following Format

"07-Jan-2010"

Date() -> "07-Jan-2010"

Regards
Anser

Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: Date Convertion function doubt
Posted: Thu Jan 07, 2010 10:32 AM

use fwh function:

cValToStr( dDate, 'dd-mmm-yyyy' )

This function works independent of the date format setting.
you can use dd, mm, mmm, mmmm in any order

for example 'mmmm dd, yyyy' produces October 23, 2009

This is the function XBrowse uses internally. We can oCol:cEditPicture in this format for date values.

Regards



G. N. Rao.

Hyderabad, India
Posts: 18
Joined: Wed Nov 04, 2009 09:41 AM
Re: Date Convertion function doubt
Posted: Thu Jan 07, 2010 11:10 AM

Hi Anserkk,

Try this:

function main ()

local a,b,c

a := Str(Day(Date()))
b := CMonth(Date())
c := Str(Year(Date()))

MSGINFO(a+ "-" +b+ "-" +c)

return nil

The result is: "7-January-2010"

Regards.

Posts: 1335
Joined: Fri Jun 13, 2008 11:04 AM
Re: Date Convertion function doubt
Posted: Thu Jan 07, 2010 11:12 AM

Dear Mr.Rao,

Thank you. cValToStr( dDate, 'dd-mmm-yyyy' ) served my purpose.

Hope I can use the same function to convert 24 Hrs. time format to 12 Hrs AM/PM format.
Where can I get more information on the formats supported by cValToStr(). In Five Wiki I did not find the write up for cValToStr(), but information on cValToChar is available.

Dear Mr.DiegoCandel,

Thank you for your support :). I was checking whether a built in function is available or not.

Regards
Anser

Posts: 1335
Joined: Fri Jun 13, 2008 11:04 AM
Re: Date Convertion function doubt
Posted: Thu Jan 07, 2010 11:31 AM

Hi all,

To convert 24 hrs time format to 12 Hrs AM/PM format we can use the Function AmPm(cTime)

Regards
Anser

Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: Date Convertion function doubt
Posted: Thu Jan 07, 2010 12:30 PM

This function is not yet documented on fivewiki, but you can search the whatsnew.txt.

no. it does not support hours and minutes still

Regards



G. N. Rao.

Hyderabad, India
Posts: 1335
Joined: Fri Jun 13, 2008 11:04 AM
Re: Date Convertion function doubt
Posted: Thu Jan 07, 2010 01:09 PM

Thank you Mr.Rao,

AMPM(cTime) served my purpose.

Regards
Anser

Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: Date Convertion function doubt
Posted: Thu Jan 07, 2010 07:16 PM
Mr. Anser

I feel dealing with date and time values separately have become things of past. Now datetime variables can be used directly.

All RDMS support datetime. Even present day DBFCDX supports datetime fields. Through ADO or RDD, we read and write datetime values directly as single variables. Why should we deal with date and time parts separately and still use the older functions?

Please look at this xHarbour code. ( Slightly different in Harbour )
Code (fw): Select all Collapse
   local tDate

   SET DATE ITALIAN
   SET TIME FORMAT TO 'HH:MM:SS PM'

   tDate  := DateTime()

   MsgInfo( TtoC( tDate ) )
   MsgInfo( TtoC( tDate, 2 ) )
   MsgInfo( cValToStr( tDate, 'DD-MMM-YYYY' ) + ' ' + TToC( tDate, 2 ) )


Results are :
08-01-2010 01:15:00 AM
01:15:00 AM
08 JAN 2010 01:15:00 AM
Regards



G. N. Rao.

Hyderabad, India
Posts: 1335
Joined: Fri Jun 13, 2008 11:04 AM
Re: Date Convertion function doubt
Posted: Fri Jan 08, 2010 06:02 AM
Dear Mr.Rao,

I am yet to learn many existing functions in xHarbour and FiveWin. I was not aware of the function DateTime() and TtoC( tDate, 2 )

I feel dealing with date and time values separately have become things of past. Now datetime variables can be used directly.

In my MS-Sql database I am using DateTime type column and I extracted the Time part from it as a seperate column in the recordset using the following Sql

Code (fw): Select all Collapse
SELECT Branch_Short_Name, Last_Upload, CONVERT(varchar(10), Last_Upload, 108) as UploadTime FROM Branches


If knew the functions DateTime() and TtoC(), then I would have extracted the Date and Time separately from a DateTime column using FiveWin itself.

I need the Time part separately for some reporting purpose.

The following command would serve my purpose
Code (fw): Select all Collapse
cValToStr( tDate, 'DD-MMM-YYYY' ) + ' ' + TToC( tDate, 2 )


Using the AMPM() with the above functions, I don't have to use the SET TIME FORMAT TO command

Once again I thank you for the support.

Regards
Anser
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: Date Convertion function doubt
Posted: Fri Jan 08, 2010 07:15 AM

I read the column values directly into a single datetime variable and use for further computations. Straight Sql.

Can always display date part or time part separately or together.

Regards



G. N. Rao.

Hyderabad, India

Continue the discussion