Topic: Convert Number to Date format
Oldest Post First
Newest Post First
Page
1
2
of 2 Next >>
Author
Message
flazaro28
Newbie
Joined: 30 Apr 2009
Location: Poland
Online Status: Offline
Posts: 35
Topic: Convert Number to Date format Posted: 18 May 2009 at 7:05am
I have a date Column in Number format which is shown below.. for example 19,730,101 imples 1973 year January -- Month and 01-Date..
How can I convert this to date format??
19,730,101, 19,780,401, 19,790,701, 19,800,701, 19,800,001, 19,801,001, 19,811,005
IP Logged
DBlank
Moderator
Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Posted: 18 May 2009 at 7:20am
There may be a better solution but here is one:
date(left(totext({ table.field}, 0,""),4)+"," + mid(totext({ table.field} ,0,""),5,2 ) +"," + right(totext({ table.field} ,0,""),2 ))
IP Logged
lockwelle
Moderator
Joined: 21 Dec 2007
Online Status: Offline
Posts: 4372
Posted: 18 May 2009 at 7:21am
local numbervar aDate:={table.field};
local numbervar aDay := aDate/10;
local numbervar aMonth;
local datevar outDate;
aDate := aDate/10;
aMonth:=aDate/10;
aDate :=aDate/10;
outDate:=dateserial(aDate, aMonth, aDay);
outdate can be shared or local, depends on what you need it for. shared is probably a better choice.
HTH
IP Logged
flazaro28
Newbie
Joined: 30 Apr 2009
Location: Poland
Online Status: Offline
Posts: 35
Posted: 18 May 2009 at 7:26am
Originally posted by DBlank There may be a better solution but here is one:
date(left(totext({ table.field}, 0,""),4)+"," + mid(totext({ table.field} ,0,""),5,2 ) +"," + right(totext({ table.field} ,0,""),2 ))
DBlank....When I try to pull this into the report it prompts me for an error
"Bad date format String"
Edited by flazaro28 - 18 May 2009 at 7:27am
IP Logged
flazaro28
Newbie
Joined: 30 Apr 2009
Location: Poland
Online Status: Offline
Posts: 35
Posted: 18 May 2009 at 7:31am
Originally posted by lockwelle
local numbervar aDate:={table.field};
local numbervar aDay := aDate/10;
local numbervar aMonth;
local datevar outDate;
aDate := aDate/10;
aMonth:=aDate/10;
aDate :=aDate/10;
outDate:=dateserial(aDate, aMonth, aDay);
outdate can be shared or local, depends on what you need it for. shared is probably a better choice.
HTH
Lockwelle...your formula prompts me for an error
IP Logged
flazaro28
Newbie
Joined: 30 Apr 2009
Location: Poland
Online Status: Offline
Posts: 35
Posted: 18 May 2009 at 7:36am
Originally posted by DBlank There may be a better solution but here is one:
date(left(totext({ table.field}, 0,""),4)+"," + mid(totext({ table.field} ,0,""),5,2 ) +"," + right(totext({ table.field} ,0,""),2 ))
Can I get the output in this format
MM/DD/YYYY..
Basically I am comparing this date to CurrentDate()
IP Logged
DBlank
Moderator
Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Posted: 18 May 2009 at 9:35am
Date function should automatically convert it to that format.
Is your number format YYYYMMDD or YYYYDDMM?
My formula is set for YYYYMMDD, if it is the other invert that last two parts of it.
Edited by DBlank - 18 May 2009 at 3:05pm
IP Logged
lockwelle
Moderator
Joined: 21 Dec 2007
Online Status: Offline
Posts: 4372
Posted: 19 May 2009 at 6:32am
depends on what the data looks like. is the field a date field or just a number...I thought it was just a number.
what I would do is create a few test formulas that will use the same logic as my original formula, but skip the part about assigning (it's causing an error) but have each formula display a different date part...one for year, one for month, one for day and compare against the field. This will allow you to see what is happening.
After a quick review, I am willing to bet that the issue is there are decimal values, which can probably be fixed by using cint(), or fix() or looking in help. But I would 'see' what the formula is doing first.
HTH
IP Logged
DBlank
Moderator
Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Posted: 19 May 2009 at 7:53am
Based on your other post I have a feeling that the number is set as YYYYDDMM. If so,
Change the code I gave you to flip the last to parts of the formula:
date(left(totext({ table.field}, 0,""),4) +"," + right(totext({ table.field} ,0,""),2 ) +"," + mid(totext({ table.field} ,0,""),5,2 ))
IP Logged
crystalsupport
Newbie
Joined: 28 Apr 2009
Location: United States
Online Status: Offline
Posts: 6
Posted: 22 May 2009 at 5:15am
Hi fiazaro28,
if you have not get your answer yet try with it
it may help you.
stringvar MyDate:=trim(totext({table.field},0,""));
// replace table.field above with yours //
if len(trim(MyDate)) = 5 then cdate(val(mid(MyDate,4,2)),val(mid(MyDate,2,2)),val(left(MyDate,1))) else if len(trim(MyDate)) = 6 then cdate(val(mid(MyDate,5,2)),val(mid(MyDate,3,2)),val(left(MyDate,2))) else cdate(0,0,0)
Regards,
Crystal Support Team
Reporting House Inc.
http://www.reportinghouse.com
IP Logged
Forum Jump
-- Select Forum --
Announcements
Talk with the Author
Self-Publishing
Job Postings
New feature request
Report Design
Data Connectivity
Technical Questions
Tips and Tricks
Crystal Xcelsius
Report Design
Data Connectivity
Writing Code
Tips and Tricks
Report Design
Data Connectivity
Writing Code
Tips and Tricks
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot delete your posts in this forum You cannot edit your posts in this forum You cannot create polls in this forum You cannot vote in polls in this forum
This page was generated in 0.047 seconds.