Re: Format Informix date -> Access
Posted in 1997
>From: Gareth Oliver <garetho@advgroup.co.nzSPAMREMOVE.informix.com>
I hate mangled email addresses!
>From: Gareth Oliver <garetho@advgroup.co.nz>
>Date: Tue, 08 Apr 1997 17:14:12 +1200
>X-Informix-List-Id: <news.36306>
>
>I am tyring to report dates from Informix 7.12 via MS Access v2.0 on
>Windows 3.1 client.
>
>Informix holds dates in the number of seconds from 01/01/70 12:00:00.
Not of its own accord, it doesn't. And the general practice is to use
1970-01-01 00:00:00 as time zero, not 1970-01-01 12:00:00.
>What I would like Access to do be able to report a date field direct
>from the Informix database, however formatting it to be able to read.
>
>i.e. at the moment March 21, 1997, 12:06:41 is being reported as
>858902801.
So, you decided to store the time in a non-standard format -- and you want
to get it printed out in a standard format -- so you'll have to write some
non-standard code to format this value. It actually isn't very hard; the
routines in <time.h> in ANSI C cover this.
FWIW: my code to convert numeric times into formatted times produces, by default:
$ timestamp 858902801858902801 = Thu Mar 20 16:06:41 1997
$
For other formats, use the -T option and the strftime(3) format you desire:
$ timestamp -T '%Y-%m-%d %H:%M:%S %Z' 858902801
858902801 = 1997-03-20 16:06:41 PST
$
>Has anyone been able to do this? The only recommendations I can find
>from people are to create another field & add it to as text. I don't
>want to do this as the schema as very large as it is.
I attach the source code for timestamp...
Yours,
Jonathan Leffler (johnl@informix.com) #include <disclaimer.h>
: "@(#)shar.sh 1.9"
#! /bin/sh
#
# This is a shell archive.
# Remove everything above this line and run sh on the resulting file.
# If this archive is complete, you will see this message at the end:
# "All files extracted"
#
# Created: Tue Apr 8 09:50:09 PDT 1997 by johnl at Informix Software Ltd.
# Files archived in this archive:
# timestamp.c
# stderr.c
# stderr.h
#
#--------------------
if [ -f timestamp.c -a "$1" != "-c" ]
then echo shar: timestamp.c already exists
else
echo 'x - timestamp.c (1241 characters)'
sed -e 's/^X//' >timestamp.c <<'SHAR-EOF'
X/*
X@(#)File: timestamp.c
X@(#)Version: 2.4
X@(#)Last changed: 97/02/04
X@(#)Purpose: Convert time as number into date
X@(#)Author: J Leffler
X@(#)Copyright: (C) JLSS 1989,1995-97
X*/
X
X#include <stdlib.h>
X#include <stdio.h>
X#include <time.h>
X#include "getopt.h"
X#include "stderr.h"
X
X#ifndef lint
Xstatic const char sccs[] = "@(#)timestamp.c 2.4 97/02/04";
X#endif
X
Xstatic const char *format = "%a %b %d %H:%M:%S %Y";
X
Xstatic void print_time(time_t t)
X{
X char buffer[256];
X
X if (strftime(buffer, sizeof(buffer), format, localtime(&t)) == 0)
X error2("Time format faulty (or too large!)", format);
X printf("%ld = %s\\n", (long)t, buffer);
X}
X
Xint main(int argc, char **argv)
X{
X time_t t;
X int opt;
X size_t i;
X
X setarg0(argv[0]);
X while ((opt = getopt(argc, argv, "T:V")) != EOF)
X {
X switch (opt)
X {
X case 'T':
X format = optarg;
X break;
X case 'V':
X version("TIMESTAMP", "2.4 (97/02/04)");
X break;
X default:
X usage("[-V][-T time-format] [time ...]");
X break;
X }
X }
X
X if (optind < argc)
X {
X for (i = optind; i < argc; i++)
X {
X t = atol(argv[i]);
X print_time(t);
X }
X }
X else
X {
X t = time((long *)0);
X print_time(t);
X }
X
X return(EXIT_SUCCESS);
X}
SHAR-EOF
chmod 444 timestamp.c
if [ `wc -c <timestamp.c` -ne 1241 ]
then echo shar: timestamp.c unpacked with wrong size
fi
# end of overwriting check
fi
#--------------------
if [ -f stderr.c -a "$1" != "-c" ]
then echo shar: stderr.c already exists
else
echo 'x - stderr.c (2266 characters)'
sed -e 's/^X//' >stderr.c <<'SHAR-EOF'
X/*
X@(#)File: stderr.c
X@(#)Version: 6.6
X@(#)Last changed: 97/04/04
X@(#)Purpose: Error reporting routines -- using stdio
X@(#)Author: J Leffler
X@(#)Copyright: (C) JLSS 1988-91,1996-97
X@(#)Product: :PRODUCT:
X*/
X
X/*TABSTOP=4*/
X/*LINTLIBRARY*/
X
X#include <stdio.h>
X#include <string.h>
X#include <stdlib.h>
X#include <stdarg.h>
X
X#include "stderr.h"
X
X#define global /* Defined here -- accessible elsewhere */
X#define NIL(x) ((x)0)
X#define MAX_CLEANUPS 32 /* Same as Standard C for atexit */
X
Xstatic char _arg0[15] = "**undefined**"; /* Actual string */
Xglobal char *arg0 = _arg0; /* Name of command */
X
X#ifndef lint
Xstatic const char sccs[] = "@(#)stderr.c 6.6 97/04/04";
X#endif /* lint */
X
Xvoid err_setcleanup(void (*p)(void))
X{
X if (atexit(p) != 0)
X error("failed to register function with atexit(3)");
X}
X
Xvoid remark2(const char *s1, const char *s2)
X{
X err_report(ERR_REM, ERR_STAT, "%s %s\\n", (s1), (s2));
X}
X
Xvoid remark(const char *s1)
X{
X err_report(ERR_REM, ERR_STAT, "%s\\n", (s1));
X}
X
Xvoid error2(const char *s1, const char *s2)
X{
X err_report(ERR_ERR, ERR_STAT, "%s %s\\n", (s1), (s2));
X}
X
Xvoid error(const char *s1)
X{
X err_report(ERR_ERR, ERR_STAT, "%s\\n", (s1));
X}
X
Xvoid stop(const char *s1)
X{
X err_report(ERR_ABT, ERR_STAT, "%s\\n", (s1));
X}
X
Xvoid usage(const char *s1)
X{
X err_report(ERR_USE, ERR_STAT, (s1));
X}
X
Xvoid version(const char *s1, const char *s2)
X{
X err_report(ERR_ERR, EXIT_SUCCESS, "%s Version %s\\n", (s1), (s2));
X}
X
Xvoid setarg0(const char *s)
X{
X char *cp;
X
X while ((cp = strrchr(s, '/')) != NIL(char *) && *(cp + 1) == '\\0')
X *cp = '\\0';
X (void)strncpy(_arg0, ((cp == NIL(char *)) ? s : cp + 1), sizeof(_arg0) - 1);
X}
X
Xvoid err_report(int flags, int estat, const char *string,...)
X{
X int i;
X va_list args;
X
X va_start(args, string);
X
X if (flags & ERR_FLUSH)
X (void)fflush(stdout);
X if (flags & ERR_USAGE)
X (void)fprintf(stderr, "Usage: %s %s\\n", arg0, string);
X else if (flags & ERR_COMM)
X {
X (void)fprintf(stderr, "%s: ", arg0);
X (void)vfprintf(stderr, string, args);
X }
X if (flags & ERR_ABORT)
X abort();
X if (flags & ERR_EXIT)
X exit(estat);
X}
SHAR-EOF
chmod 444 stderr.c
if [ `wc -c <stderr.c` -ne 2266 ]
then echo shar: stderr.c unpacked with wrong size
fi
# end of overwriti