Solved

Date format - ShortDateFormat

Posted on 1998-12-28
2
199 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 100 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
loading dll from external path 1 210
Newbie Thread Programming 1 139
FMX enumerated colours 2 84
Delphi: how to implement a User Shortcut mapper? 1 94
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…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
Concerto provides fully managed cloud services and the expertise to provide an easy and reliable route to the cloud. Our best-in-class solutions help you address the toughest IT challenges, find new efficiencies and deliver the best application expe…

914 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now