Page 1 of 1

Date Convertion function doubt

PostPosted: Thu Jan 07, 2010 9:57 am
by anserkk
Hi,

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

"07-Jan-2010"

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

Regards
Anser

Re: Date Convertion function doubt

PostPosted: Thu Jan 07, 2010 10:32 am
by nageswaragunupudi
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.

Re: Date Convertion function doubt

PostPosted: Thu Jan 07, 2010 11:10 am
by DiegoCandel
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.

Re: Date Convertion function doubt

PostPosted: Thu Jan 07, 2010 11:12 am
by anserkk
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

Re: Date Convertion function doubt

PostPosted: Thu Jan 07, 2010 11:31 am
by anserkk
Hi all,

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

Regards
Anser

Re: Date Convertion function doubt

PostPosted: Thu Jan 07, 2010 12:30 pm
by nageswaragunupudi
This function is not yet documented on fivewiki, but you can search the whatsnew.txt.

no. it does not support hours and minutes still

Re: Date Convertion function doubt

PostPosted: Thu Jan 07, 2010 1:09 pm
by anserkk
Thank you Mr.Rao,

AMPM(cTime) served my purpose.

Regards
Anser

Re: Date Convertion function doubt

PostPosted: Thu Jan 07, 2010 7:16 pm
by nageswaragunupudi
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: Select all  Expand view
  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

Re: Date Convertion function doubt

PostPosted: Fri Jan 08, 2010 6:02 am
by anserkk
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: Select all  Expand view
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: Select all  Expand view
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

Re: Date Convertion function doubt

PostPosted: Fri Jan 08, 2010 7:15 am
by nageswaragunupudi
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.