Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Date format - ShortDateFormat

Posted on 1998-12-28
2
Medium Priority
?
220 Views
Last Modified: 2010-04-04
I have to convert a date to a string and sometime back to a date for sorting purpose.  The following works fine:

  SysUtils.ShortDateFormat := 'DD/MM/YYYY  HH:MM AM/PM';

I would prefer the following format

  SysUtils.ShortDateFormat := 'DD MMM YYYY  HH:MM AM/PM';

The problem is that it won't let me convert back to datetime with the function StrToDateTime. Any suggestions ?
0
Comment
Question by:moonrise
2 Comments
 

Accepted Solution

by:
teechong earned 300 total points
ID: 1353403
You should always maintain the date and time in a TDateTime variable and use the FormatDateTime function whenever you need to display it.

Keeping it in the native TDateTime format lets you perform calculations and sorting.

var
ACurrentDate : TDateTime;

..
FormatDateTime ('dd mmm yyyy hh:nn AM/PM', ACurrentDate);

The StrToDateTime function has dependency on the Window's Regional settings and therefore is not reliable especially if your code is going to be run on other PCs.
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1353404
moonrise.. Would you please show me an example of a date that has been displayed by the function SysUtils.ShortDateFormat := 'DD MMM YYYY  HH:MM AM/PM';
and tell me what you want to get when you convert the string back to date....

-Viktor
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses

963 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question