?
Solved

date format 'yymmdd' problem

Posted on 2004-03-23
7
Medium Priority
?
407 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 200 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

Independent Software Vendors: 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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses
Course of the Month10 days, 16 hours left to enroll

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