Operating System - OpenVMS
1753907 Members
8932 Online
108810 Solutions
New Discussion юеВ

Re: Date in the Format YYMMDD

 
SOLVED
Go to solution
Niall76
Frequent Advisor

Date in the Format YYMMDD

Hi,

I was wondering if someone could provide me with the correct function/syntax to get the date the format YYMMDD, so 03-Dec-2010 will display as 101203.

Thanks,

Niall
8 REPLIES 8
Steven Schweda
Honored Contributor
Solution

Re: Date in the Format YYMMDD

You want _the_ correct anything? There's
seldom only one correct way. If "the date"
means today's date, then this seems to work:

alp $ write sys$output f$extract( 2, 8, f$cvtime( f$time()))- "-"- "-"
101203

If you want to convert some arbitrary date,
then you could replace "f$time()" with the
appropriate string:

alp $ write sys$output f$extract( 2, 8, f$cvtime( "25-Dec-2010"))- "-"- "-"
101225

HELP LEXICALS
Steven Schweda
Honored Contributor

Re: Date in the Format YYMMDD

> HELP LEXICALS

Hmmm. Taking my own advice, for today's
date, there's yet another default value in
F$CVTIME():

alp $ write sys$output f$extract( 2, 8, f$cvtime())- "-"- "-"
101203
Steven Schweda
Honored Contributor

Re: Date in the Format YYMMDD

> [...] There's
> seldom only one correct way. [...]

alp $ t = f$time()
alp $ write sys$output f$extract( 2, 2, f$cvtime( t, , "YEAR"))+ -
_alp $ f$cvtime( t, , "MONTH")+ f$cvtime( t, , "DAY")
101203

As usual, many things are possible.
Hein van den Heuvel
Honored Contributor

Re: Date in the Format YYMMDD


>> the correct function/syntax

In what context / language
DECforms? TDMS? / Cobol? Basic?
What is the representation of the source date?
What need to happen for 19xx dates? 21xx?
Should there be a sliding window?

As Steven wrote, in DCL one can just take the leading century characters away.
The easiest way to do that, and most sloppy way, is:

$ write sys$output f$cvtime(,,"DATE") -"20"-"-"-"-"

Hein
Jon Pinkley
Honored Contributor

Re: Date in the Format YYMMDD

Niall,

If you want the dates to be displayed this way in direcotory or other utilities that use the LIB$ routines like LIB$FORMAT_DATE_TIME to format dates, then you can define the logical LIB$DT_FORMAT to one of many format types.

See sys$manager:systartup_vms.template (and search for date), and SYS$STARTUP:LIB$DT_STARTUP.COM for the predefined format specifiers.

Here's an example: (This assumes LIB$DT_STARTUP was used in startup)

$ sho log lib$dt_format
"LIB$DT_FORMAT" = "LIB$DATE_FORMAT_001" (LNM$SYSTEM_TABLE)
= "LIB$TIME_FORMAT_001"
$ dir sys$login:login.com;/date

Directory ROOT$USERS:[JON]

LOGIN.COM;245 12-DEC-2009 11:56:30.00

Total of 1 file.
$ def lib$dt_format lib$date_format_026
$ dir sys$login:login.com;/date

Directory ROOT$USERS:[JON]

LOGIN.COM;245 091212

Total of 1 file.
$ def lib$dt_format lib$date_format_026,lib$time_format_001
%DCL-I-SUPERSEDE, previous value of LIB$DT_FORMAT has been superseded
$ dir sys$login:login.com;/date

Directory ROOT$USERS:[JON]

LOGIN.COM;245 091212 11:56:30.00

Total of 1 file.
$ sho log lib$dt_format
"LIB$DT_FORMAT" = "LIB$DATE_FORMAT_026" (LNM$PROCESS_TABLE)
= "LIB$TIME_FORMAT_001"
"LIB$DT_FORMAT" = "LIB$DATE_FORMAT_001" (LNM$SYSTEM_TABLE)
= "LIB$TIME_FORMAT_001"
$ deas lib$dt_format
$ dir sys$login:login.com;/date

Directory ROOT$USERS:[JON]

LOGIN.COM;245 12-DEC-2009 11:56:30.00

Total of 1 file.
$

Jon
it depends
Niall76
Frequent Advisor

Re: Date in the Format YYMMDD

Hi guys,

Thanks for your responses; it was 'my bad'. What I want is to be able to define today's date in a com file so I will to be able to copy a file with today's date as part of the file name. So something like this:

$ write sys$output f$extract( 2, 8, f$cvtime( f$time()))- "-"- "-"
$!
$! **define date (below) to be the output of the above**
$ scp2 games_'date'.XML
"root@10.10.10.100::/srv/games.xml"

Sorry for the confusion.

Regards,
Niall
lalo57
Advisor

Re: Date in the Format YYMMDD

Niall, pls try with this dcl example and change the sentences as you consider

$ set noon
$ set nover
$ wfechahoy = f$cvtime("today","comparison",)
$ aammdd = f$extract(2,2,wfechahoy) + f$extract(5,2,wfechahoy) + f$extract(8,2,wfechahoy)
$ sh symb aammdd
$ descrip_file = "FILE_DATE_" + aadddd + ".XML;"
$
$ dir 'descrip_file
$!

Good luck,
Eduardo
lalo57
Advisor

Re: Date in the Format YYMMDD

Sorry Niall, i've updated the lines of this example:


$!Start DCL
$ set noon
$ set nover
$ wfechahoy = f$cvtime("today","comparison",)
$ aammdd = f$extract(2,2,wfechahoy) + f$extract(5,2,wfechahoy) + f$extract(8,2,wfechahoy)
$ sh symb aammdd
$ descrip_file = "FILE_DATE_" + aammdd + ".XML;"
$
$ dir sys$startup:ope*.log /out='descrip_file
$ dir 'descrip_file
$!
$!End DCL