Print Page | Close Window

HOWTO: Format date/time values

Printed From: Codejock Forums
Category: Codejock Products
Forum Name: Report Control
Forum Description: Topics Related to Codejock Report Control
URL: http://forum.codejock.com/forum_posts.asp?TID=18203
Printed Date: 29 September 2024 at 3:27am
Software Version: Web Wiz Forums 12.04 - http://www.webwizforums.com


Topic: HOWTO: Format date/time values
Posted By: RichardJ
Subject: HOWTO: Format date/time values
Date Posted: 11 April 2011 at 9:31am

I am adding some date/time values as CXTPReportRecordItemDateTime items and I would like to format the date and time string displayed in the cell.  How do I do this?

Using Column->SetFormatString() with a string such as "dd/MM/yyyy HH:mm:ss" (the value from GetLocaleInfo()) doesn't do the job.


Product: Xtreme Toolkit Pro (MFC) version v15.0
Platform: Windows XP (32bit) - SP 3
Language: VC++ 2010




Replies:
Posted By: mgampi
Date Posted: 11 April 2011 at 3:52pm
Hi;
I do it this way:

   Item=AddItem(new CXTPReportRecordItemDateTime(COleDateTime(Date)));
    Item->SetFormatString("%d.%m.%Y");


I can't find a SetFormatString() function in CXTPReportColumn class?!?!


-------------
Martin

Product: Xtreme Toolkit v 19.0.0, new Projects v 19.1.0
Platform: Windows 10 v 1909 (64bit)
Language: VC++ 2017


Posted By: RichardJ
Date Posted: 12 April 2011 at 5:12am

Thanks for the answer.

My mistake, SetFormatString() is on the item not the column.

The documentation for the method is incorrect here.  CXTPReportRecordItem::SetFormatString says to look at the sprintf format specifications whereas for CXTPReportRecordDateTimeItem::SetFormatString I should be looking at the strftime format specifications.  The sprintf format specifications don't actually have any codes for dates or times.

Unfortunately it looks like it's going to be tricky to use the user's/system preferences to do the formatting since this would require translating from one format specification to another.



Posted By: RichardJ
Date Posted: 12 April 2011 at 5:24am
On further investigation, the formatting code %c respect's the user's settings.



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.04 - http://www.webwizforums.com
Copyright ©2001-2021 Web Wiz Ltd. - https://www.webwiz.net