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 John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to convert number to date 1

Status
Not open for further replies.

rb2005

Programmer
Mar 7, 2005
110
US
I have a column which is holding data like 200601. I want to convert this like 01/06 or 01/2006 or Jan 2006 or any date format. Anyone has any clue.
 
None of those are date formats, they are string representations of partial dates.

I'd convcert it to a date using:

cdate(val(left({table.field},4)),val(mid({table.field},5,2)),1)

Now you can right click the formula and format it however you like using format field->date

-k
 
I guess I need totext to convert number to string then only I can use left function
 
If you tried
Code:
ToText((cdate(val(left({table.field},4)),val(mid({table.field},5,2)),1)), "MMM yyyy")
you'd get Jan 2006 for 200601. Is that what you want?

[yinyang] Madawc Williams (East Anglia, UK). Using Windows XP & Crystal 10 [yinyang]
 
Multiply by 100, add 1 and you get:

20060101

Then convert to a date using the NumberToDate() function, then format as desired.

Software Sales, Training, Implementation and Support for Macola, eSynergy, and Crystal Reports
 
NumberToDate() is not available in Crystal.

ToText((cdate(val(left({table.field},4)),val(mid({table.field},5,2)),1)), "MMM yyyy")
also not working.
 
Which version of Crystal? You must have an early one, definitely before 8.5.

'Not working' could mean several different things; please clarify.

[yinyang] Madawc Williams (East Anglia, UK). Using Windows XP & Crystal 10 [yinyang]
 
I am using 10.5
ToText((cdate(val(left({table.field},4)),val(mid({table.field},5,2)),1)), "MMM yyyy")
I am trying to convert a number to date. So left function is failing. I am getting an error.
 
Yeah, the downside of posts such as this is that you say you have a column, not the data type...

Try:

stringvar MyDate:=totext({table.field},0,"");
cdate(val(left(MyDate,4)),val(mid(MyDate,5,2)),1)

-k
 
thanks synapsevampire. Finally it works great.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top