Solved

Date format - ShortDateFormat

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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Delphi 2010 Export to pdf 2 253
SIM number for APK using Delphi 10 2 363
Printing problem 2 72
Firemonkey webbrowser scrollbars ? 1 4
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…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

762 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

23 Experts available now in Live!

Get 1:1 Help Now