Article 128526 of comp.os.vms:
Path: nntpd.lkg.dec.com!pa.dec.com!decuac.dec.com!haven.umd.edu!purdue!lerc.nasa.gov!magnus.acs.ohio-state.edu!math.ohio-state.edu!howland.reston.ans.net!newsfeed.internetmci.com!newsxfer.itd.umich.edu!jobone!fiesta.srl.ford.com!eccdb1.pms.ford.com!mail.fc.ford.com!MMILLER4
From: mmiller4@mail.fc.ford.com
Newsgroups: comp.os.vms
Subject: Re: [Q] Convert Date/Time String to VMS Internal Time
Date: 4 Sep 1995 15:21:11 GMT
Organization: Ford Credit
Lines: 62
Message-ID: <42f5h7$r6d@eccdb1.pms.ford.com>
References: <423mma$llm@spruce.citicorp.com>
Reply-To: mmiller4@mail.fc.ford.com
NNTP-Posting-Host: 19.59.49.253

In article <423mma$llm@spruce.citicorp.com>, pankaj.arora@citicorp.com (Pankaj Arora) writes:
> I tried & tried using the VMS calls LIB$CONVERT_DATE_STRING &
> LIB$INIT_DATE_TIEM_CONTEXT, but somehow it never works. I need
> to convert the date/time string in YYYYMMDDHHMMSS format to VMS
> internal date-time format. 
>
Here is a  piece of code that should do the job.  Note that the input input
date format is yyyymmdd hh:mm:ss.cc.  It is left as an exercise to the reader
to make the necessary modifications.
-------------------------------------------------------------------------------
#include <descrip.h>
#include <libdef.h>
#include <libdtdef.h>
#include <time.h>
#include <ssdef.h>
#include <stddef.h>
#include <stdio.h>

/******************************************************************************
 *				asccm_to_bin
 ******************************************************************************
 * This routine converts an input string date in yyyymmdd format to a BIN (VMS
 * quadword) format date.  The time in hh:mm:ss.cc format may also be included
 * as part of the input string seperated from the date with a space.  If no
 * time is specified, 00:00:00.00 is assumed.  This routine will return zero
 * (0) if the conversion was successful or it will return the VMS Status from
 * the applicable LIB$ routine if the conversion was unsuccessful.
 ******************************************************************************/
int asccm_to_bin(char *bin, char *in_ptr, int in_len)
{
 static int usr_cntxt;
 int st = 0;
 struct dt_default_fields flags = {1, 1, 1, 1, 1, 1, 1};
 $DESCRIPTOR(in_dt, in_ptr);
 
 in_dt.dsc$w_length = in_len;

 /* Initialize the user context for the ASCCM date format if it hasn't already
  * been done. */

 if (usr_cntxt == 0) {  /* yyyymmdd hh:mm:ss.cc */
     $DESCRIPTOR(ini_str, "|!Y4!MN0!D0 !HH4:!MM:!SS.!C2|");
     if ((st = LIB$INIT_DATE_TIME_CONTEXT(&usr_cntxt,
                                          &LIB$K_INPUT_FORMAT,
                                          &ini_str)) & SS$_NORMAL)
         st = 0;
 }
 if (!st && ((st = LIB$CONVERT_DATE_STRING(&in_dt,
                                           bin,
                                           &usr_cntxt,
                                           &flags,
                                           0,
                                           0)) & SS$_NORMAL))
     st = 0;
 return st;
}
-------------------------------------------------------------------------------
Michael G. Miller                       "Just another number in the grand
Ford Motor Credit Company               design." -- Boston
mmiller4@fc.ford.com

        -- Views are mine and not necessarily those of my employer. --


