Outputting a VMS quadword time in UNIX


 
Thread Tools Search this Thread
Top Forums Programming Outputting a VMS quadword time in UNIX
# 1  
Old 08-05-2004
Outputting a VMS quadword time in UNIX

I am writing a C program under UNIX which needs to write out a VMS quadword time for the current time (to a file)
This quadword is the number of 100 nanoseconds since 1858.
I know I can easily get the time in secs since 1970 in UNIX/C.

The problem is how to multiply by a rather large number (convert to nanoseconds) and add a rather large number (difference between 1858 and 1970 in 100 nanoseconds) in a language that hasnt got quadwords.
# 2  
Old 08-06-2004
You want to create a VMS quadword - they are 64 bit unsigned integers. By the way, the quadword date stores information down to the millisecond (1000th of a second).

You have to know what a long is on your Unix machine - they are not all the same - what Driver is asking. If a long is 32 bits, then you need to write out a long long. If a long on your unix box is 64 bits, then you need to write out a long. That's problem one.

Problem two. Is your Unix system big endian or small endian? For VMS to read the value it has to be written small endian format.

VMS uses what is called a Modified Julian Date - mjd.
This is a simple algorithm that takes two dates and returns the number of days between them. The VMS mjd is the number of days since Jan 17, 1858 which for this program is 0,0,0 as arguments (gives a zero day), so you only need to know the number of days for the date you are working with.

You need to add the number of hours * 3600, plus the number of minutes * 60, plus the number of seconds to your you result (as milliseconds).

This code returns an int - on my machine this is a 32 bit long.
Arguments are the year as a number (eg, 1999), the month (1-12), and the day (1-31)

Code:
int mjd(int dateyear,int datemonth,int dateday)
{
  int y = dateyear;
  int m = datemonth - 1;
  int d = dateday - 678882;
  d += 146097 * (y / 400);
  y %= 400;
  if (m >= 2){ 
      m -= 2; 
  }else { 
  	  m += 10; 
  	  --y; 
  }
  y += (m / 12);
  m %= 12;
  if (m < 0) { 
  	  m += 12; 
  	  --y; 
  }
  d += (306 * m + 5) / 10;
  d += 146097 * (y / 400);
  y %= 400;
  if (y < 0) { 
  	  y += 400; 
  	  d -= 146097; 
  }
  d += (y & 3) * 365;
  y >>= 2;
  d += 1461 * (y % 25);
  y /= 25;
  d += (y & 3) * 36524;
  return d;
}

# 3  
Old 08-06-2004
Thanks very much for this help.
I didnt know 'long long' existed. I tried it out and that solves the hardest bit of the problem.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Programming

Arduino UNIX Time - Syncing Computer UNIX Time to Arduino Time with Python

Just finished a quick Python script to send the current unix time over to the Arduino from macOS, so in the absence of GPS or some other way to get the unix timestamp (epoch time) to the Arduino, I can get my macOS and Arduino UNO synced to within a second. Normally, when the Arduino starts... (9 Replies)
Discussion started by: Neo
9 Replies

2. Shell Programming and Scripting

Convert UTC time into current UNIX sever time zone

Hi guys thanks for the help for my previous posts.Now i have a requirement that i download a XMl file which has UTC time stamp.I need to convert UTC time into Unix server timezone. For ex if the time zone of unix server is CDT then i need to convert into CDT.whatever may be the system time... (5 Replies)
Discussion started by: mohanalakshmi
5 Replies

3. Shell Programming and Scripting

Adding time to date time in UNIX shell scipting

I needed some help in adding a duration (in seconds) to a start time (in hhmmss format) and a start date (in mmddyy format) in order to get an end date and end time. The concept of a leap year is also to be considered while incrementing the day. The code/ function that I have formed so far is as... (3 Replies)
Discussion started by: codehelp04
3 Replies

4. UNIX for Dummies Questions & Answers

Converting string date time to unix time in AWK

I'd like to convert a date string in the form of sun aug 19 09:03:10 EDT 2012, to unixtime timestamp using awk. I tried This is how each line of the file looks like, different date and time in this format Sun Aug 19 08:33:45 EDT 2012, user1(108.6.217.236) all: test on the 17th ... (2 Replies)
Discussion started by: bkkid
2 Replies

5. Shell Programming and Scripting

How to get time duration between two human readable time stamp in Unix?

Here is two time I have: Jul 12 16:02:01 Jul 13 01:02:01 and how can I do a simple match to get difference between two time which is 09:00:00 Thanks in advance. (3 Replies)
Discussion started by: ford99
3 Replies

6. UNIX for Dummies Questions & Answers

SFTP VMS to UNIX

All I am a VMS guy just learning UNIX. My first task is to SFTP files from VMS to UNIX in BATCHMODE without having to enter a password. Note that using SFTP interactively works just fine. I have followed some specific instructions provided by a vendor with no success. I have also read... (0 Replies)
Discussion started by: randyhouse
0 Replies

7. Shell Programming and Scripting

Tcl: Outputting Unix console without Buffering

Hi, I'm have a tcl application using expect. The application is connecting to a unix box and is running a script. What i need my app to do is show the output of the console as the script runs in realtime. At the moment, it my app is waiting until the script finishes and then dumps what is... (0 Replies)
Discussion started by: Phi01
0 Replies

8. UNIX for Advanced & Expert Users

How To Provide Time Sync Using Nts-150 Time Server On Unix Network?

can anybody tel lme,how to instal NTS -150 on a unix network,it needs some patch to fetch time frm serve,,?? (2 Replies)
Discussion started by: pesty
2 Replies

9. UNIX for Dummies Questions & Answers

VAX/VMS anyone??

Hope someone can help here..... I'm looking for some websites with info on VAX/VMS. I've tried google, yahoo and other search engines, but to no avail. Am I looking in the correct place?? :confused: (5 Replies)
Discussion started by: GandalfWhite
5 Replies
Login or Register to Ask a Question