Solved

date format 'yymmdd' problem

Posted on 2004-03-23
7
397 Views
Last Modified: 2010-04-05
I have a date format of yymmdd, when I WriteIn my yymmdd into my output file, it is suppose to be 040324. Why does it only appears 40324?

I'm using myDate.Text := FormatDateTime('yymmdd', Date);
StrToInt(myDate.Text);

How can I make it to appear as 040324?
0
Comment
Question by:cybermilky
[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
7 Comments
 
LVL 12

Expert Comment

by:esoftbg
ID: 10665111
because as string is '040324'
but as Integer is   40324
emil
0
 
LVL 17

Accepted Solution

by:
mokule earned 50 total points
ID: 10665129
Hi
where it appears 40324 in myDate.Text ??
or after convertion StrToInt. When You converted string to integer You.ve got integer 40324.
You can convert such an integer two 6 digit string by
Edit1.Text := FormatDateTime('yymmdd',Now);
Edit2.Text := Format('%6.6d',[StrToInt(FormatDateTime('yymmdd',Now))]);
0
 
LVL 3

Expert Comment

by:JDuncan
ID: 10668799
You can write string type using writln as well as int so you do not need to do the strtoint conversion
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Author Comment

by:cybermilky
ID: 10674105
Hi mokule,

It works!!!
It's like this... i have a TEdit to get the 040324 in my variable 'myDate'. Then,
SendDate := StrToInt(myDate.Text);
Writeln(F,Format('%-8.6d',[SendDate{strtoint(myDate.Text)}]));

What does %8.6d stands for?
0
 
LVL 17

Expert Comment

by:mokule
ID: 10675040
function Format converts data contained in [] to a string.
Here we converts only an integer SendDate.
%-8.6d is a format string informing how to convert
d - decimal convertion
8 - width - string will have 8 characters
6 - precision - string must have 6 digits (the resulting string is left-padded with zeros)
-  - left justification
0
 
LVL 12

Expert Comment

by:esoftbg
ID: 10675190
I think it is very strange to make double conversion:
1. SendDate := StrToInt(myDate.Text);
2. Writeln(F,Format('%-8.6d',[SendDate]));
Isn't it more easy by one step:
Writeln(F, myDate.Text);
because myDate.Text is in right format (for example '040324')

emil
0
 
LVL 17

Expert Comment

by:mokule
ID: 10675413
You're absolutly right esoftbg.
As for me I presume that cybermilky has some reason to convert it to integer first.
Doing something between this convertions or I don't know what.
Mind that he don't use any separators in date format like he want to be an integer.
cybermilky must judge whether there is any sensible reason to convert it to integer.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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 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…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
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 …

695 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