Solved

Date format - ShortDateFormat

Posted on 1998-12-28
2
213 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

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…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Suggested Courses
Course of the Month11 days, 1 hour left to enroll

631 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