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

Changing text to date format

Status
Not open for further replies.

Shazza

Technical User
Aug 21, 2000
38
0
0
NZ

I am trying to change a string 'dd/mm/yy' to a date format. The database field is not a date/time field - only a date field.
 
I would just pick it apart and put it into a date via a formula such as:

If NumericText(Left({table.datestring},2))
and NumericText(Mid({table.datestring},4,2))
and NumericText(Right({table.datestring},2))
Then
If ToNumber(Right({Table.datestring},2)) > XX (Where XX = lowest year available in the 1900's)
Then Date(Year(ToNumber((Right({Table.datestring},2)) + 1900),
Month(ToNumber(Mid({table.datestring},4,2))),
Day(ToNumber(Left({table.datestring},2)))
Else Date(Year(ToNumber((Right({Table.datestring},2)) + 2000),
Month(ToNumber(Mid({table.datestring},4,2))),
Day(ToNumber(Left({table.datestring},2)))
Else Date(1900,1,1)

I use 1/1/1900 as my error date as that is one that is not used in any of our applications, and is easy to search for.
 
You can use a very simple way to accomplish what is needed. Just use the DateValue function. As a simple example, do two formulas as follows (you can use one formula only, it depends on your needs):
The first formula would create a StringVar variable and store the date with the format "dd/mm/yy":

StringVar DateString := "23/5/99"

The second formula would display the string that is converted to date type:

StringVar DateString;
DateVar DateStyle := DateValue(DateString);
DateStyle

Note: The output format from the DateValue would be "MM/DD/YYYY". I am not sure whether you want that.

I hope that would help. :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top