Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Printing Date Format in dd/mm/yyyy 1

Status
Not open for further replies.

ummul21

Programmer
Jun 23, 2003
21
SG
Hi,
I have a string field in my database to store date. the date format is dd/mm/yy (31/05/03).

I have problem to convert the string to date type.
I tried to use cdate function, but it will change the date format to 03/05/31.

I also tried to use below formula :

cdate(val(mid ({attendance.trdate},1,2)),
val(mid({attendance.trdate},3,2)),
val(mid({attendance.trdate},5,2)))

which I get the result 31/05/3..... I don't know why the year become 3 not 03....

Pls help.....
 
Change :
cdate(val(mid ({attendance.trdate},1,2)),
val(mid({attendance.trdate},3,2)),
val(mid({attendance.trdate},5,2)))

To :
cdate(val(mid ({attendance.trdate},5,2)),
val(mid({attendance.trdate},3,2)),
val(mid({attendance.trdate},1,2)))


Reebo
Scotland (Sunny with a Smile)
 
Thanks Reeboo,

I tried to change it, but it is showing me 3/05/31 instead of 31/05/03 .

The actual date should be 31st May 03
 
How exactly is the date stored? you said dd/mm/yy, does this include the /? If it does you can use:

cdate({table.field})

If the date is actually stored as ddmmyy, i.e. 020103 for 2nd Jan 2003, then you can use :

cdate(picture({table.field},"xx/xx/xx"))

Let me know how you get on.......

Reebo
Scotland (Sunny with a Smile)
 
Actually in my database i have two columns for date:
1 ) column tdate in dd/mm/yy format
2 ) column trans_date in ddmmyy format

the problem is when I use cdate function to convert the string to date format, it will take the date as year and the year as date.

for example if I use cdate({table.field})
02nd Jan 03 will come out as 03rd Jan 02

and if I use
cdate(val(mid ({attendance.trdate},1,2)),
val(mid({attendance.trdate},3,2)),
val(mid({attendance.trdate},5,2)))
02nd Jan 03 will come out as 02nd Jan 3 (as you can see, the year is rounded from 03 to 3 if val() func is used..
 
Try ToText, as follows:
Totext ({attendance.trdate}, "dd/MM/yy")

Much easier and more flexible

Madawc Williams
East Anglia, Great Britain
 
Thanks for your opinion Madawc,

Actually my field already in string type, I want to change it to date type so that i can use it in my selection criteria.
 
You don't ToText a string, Madawc.

WhilePrintingRecords;
StringVar NewDate;

If Val(Right({Your.DateString},2)) < 50
Then NewDate := &quot;20&quot; + Right({Your.DateString},2)
Else NewDate := &quot;19&quot; + Right({Your.DateString},2);

NewDate := NewDate + &quot;/&quot; + Mid({Your.DateString},3,2) + &quot;/&quot; + Mid({Your.DateString},1,2);

DTSToDate(NewDate);

Naith
 
Thanks Naith...

It is working fine with my report

[smile2]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top