- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
I have a date variable with the value as '7/30/2019 14:43' and I want to convert it into a character variable keeping the same format how do I do this? Any help will be greatly appreciated.
Thanks,
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
new_var = putn(old_var, vformat(old_var));new_var2 = vvalue(old_var);
Use PUTN() to convert it to a character variable.
Use VFORMAT() to get the format that was displaying the variable and apply it in the conversion.
or Use VVALUE to get the formatted value into a character.
EDIT: Modified as per @Tom suggestions
@Aidaan_10 wrote:
Hi,
I have a date variable with the value as '7/30/2019 14:43' and I want to convert it into a character variable keeping the same format how do I do this? Any help will be greatly appreciated.
Thanks,
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Character variables cannot have the same format as numeric variables.
If you want the character variable to appear the same as the formatted numeric variable ... why? What is the benefit of changing the variable type from numeric to character if it appears the same to us humans?
Paige Miller
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Look which format is used to display this datetime variable and use that in a put() function.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
new_var = putn(old_var, vformat(old_var));new_var2 = vvalue(old_var);
Use PUTN() to convert it to a character variable.
Use VFORMAT() to get the format that was displaying the variable and apply it in the conversion.
or Use VVALUE to get the formatted value into a character.
EDIT: Modified as per @Tom suggestions
@Aidaan_10 wrote:
Hi,
I have a date variable with the value as '7/30/2019 14:43' and I want to convert it into a character variable keeping the same format how do I do this? Any help will be greatly appreciated.
Thanks,
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Huh? If it is a DATETIME value then you would need PUTN() instead of PUTC() as the N/C refers in the data type that is being formatted. The output of applying a format is always character.
Note that you can use the VVALUE() function to see the formatted value of a variable without first having find out what format, if any, is attached to it.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
new_var=vvalue(old_var) worked very well. Thank you so much