Solved

Date format - ShortDateFormat

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

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

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

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
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…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

770 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