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

Return todays date in a specific format 2

Status
Not open for further replies.

huytonscouser

Programmer
Oct 14, 2011
88
US
I need to display yyyymmdd as a numeric field in a specific format

i.e. todays date i want to be a numeric field and return 20,120,104

any months or days < 10 should have a leading zero.

i was gathering the pieces via :=

numbervar myyear :=(year(currentdate)); //this returns 2012.00
numbervar mymonth :=(month(currentdate)); // this returns 1.0
numbervar myday :=(day(currentdate)); // this returns 4.0




Now i just want a single numbervar 20,120,104
off course recognizing days/months < 10


Thanks in advance for any help
 
huytonscouser,

The following should return what you seek:

{@YourFormula}
Code:
[blue]ToNumber[/blue]([blue]ToText[/blue]([blue]DateValue[/blue]([blue]CurrentDateTime[/blue]),"yyyyMMdd"))

Cheers!

Mike
---------------------------------------------------------------
"To be alive is to revel in the moments, in the sunrise and the sunset, in the sudden and brief episodes of love and adventure,
in the hours of companionship. It is, most of all, to never be paralyzed by your fears of a future that no one can foretell."
 
You are most welcome huytonscouser! [smile] Not going to lie, I was fighting with a more complex solution when the above "ah-ha" struck me.

Saved to my own notes for future use, thanks for the opportunity!

Cheers!

Mike
---------------------------------------------------------------
"To be alive is to revel in the moments, in the sunrise and the sunset, in the sudden and brief episodes of love and adventure,
in the hours of companionship. It is, most of all, to never be paralyzed by your fears of a future that no one can foretell."
 
Yes, i sometimes cannot see the wood from the trees and go off down the rabbit hole :) , and always forget about using multiple args/calls in a single line, like you provided.
 
Mike, how would i go about getting the numbervar 20,120,104 to display as mmddyyyy ? thanks
 
huytonscouser,

Do you wish to convert a NumberVar / "Number" Data-field, or simply restate today's date in a different format?

If the latter, change my above solution to as follows:
{@YourFormulaField}
Code:
[blue]ToNumber[/blue]([blue]ToText[/blue]([blue]DateValue[/blue]([blue]CurrentDateTime[/blue]),"MMddyyyy"))

If the former (or something else), please advise and I will work on "Number-Input" solution. [smile]

Cheers!

Mike
---------------------------------------------------------------
"To be alive is to revel in the moments, in the sunrise and the sunset, in the sudden and brief episodes of love and adventure,
in the hours of companionship. It is, most of all, to never be paralyzed by your fears of a future that no one can foretell."
 
Table.datekey is a number datatype and returns 20,120,104 (for today)

i'd like to create a formula which converts this to mm/dd/yyyy

thanks
 
Try the following to convert to a string in the desired format:

stringvar x := totext({table.datekey},0,"");
mid(x,5,2)+"/"+right(x,2)+"/"+left(x,4)

Or to convert this to an actual date that you can then format as desired, use:

date(val(left(x,4)),val(mid(x,5,2)),val(right(x,2)))

Then right click on this->format field->date->select the desired format.

-LB
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top