Date Convertion function doubt

Date Convertion function doubt

Postby anserkk » Thu Jan 07, 2010 9:57 am

Hi,

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

"07-Jan-2010"

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

Regards
Anser
User avatar
anserkk
 
Posts: 1333
Joined: Fri Jun 13, 2008 11:04 am
Location: Kochi, India

Re: Date Convertion function doubt

Postby nageswaragunupudi » 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
User avatar
nageswaragunupudi
 
Posts: 10646
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: Date Convertion function doubt

Postby DiegoCandel » 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.
DiegoCandel
 
Posts: 18
Joined: Wed Nov 04, 2009 9:41 am

Re: Date Convertion function doubt

Postby anserkk » 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
User avatar
anserkk
 
Posts: 1333
Joined: Fri Jun 13, 2008 11:04 am
Location: Kochi, India

Re: Date Convertion function doubt

Postby anserkk » 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
User avatar
anserkk
 
Posts: 1333
Joined: Fri Jun 13, 2008 11:04 am
Location: Kochi, India

Re: Date Convertion function doubt

Postby nageswaragunupudi » 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
User avatar
nageswaragunupudi
 
Posts: 10646
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: Date Convertion function doubt

Postby anserkk » Thu Jan 07, 2010 1:09 pm

Thank you Mr.Rao,

AMPM(cTime) served my purpose.

Regards
Anser
User avatar
anserkk
 
Posts: 1333
Joined: Fri Jun 13, 2008 11:04 am
Location: Kochi, India

Re: Date Convertion function doubt

Postby nageswaragunupudi » Thu Jan 07, 2010 7: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: Select all  Expand view  RUN
  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
User avatar
nageswaragunupudi
 
Posts: 10646
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: Date Convertion function doubt

Postby anserkk » Fri Jan 08, 2010 6: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: Select all  Expand view  RUN
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  RUN
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
User avatar
anserkk
 
Posts: 1333
Joined: Fri Jun 13, 2008 11:04 am
Location: Kochi, India

Re: Date Convertion function doubt

Postby nageswaragunupudi » Fri Jan 08, 2010 7: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
User avatar
nageswaragunupudi
 
Posts: 10646
Joined: Sun Nov 19, 2006 5:22 am
Location: India


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 41 guests