BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Balli
Obsidian | Level 7

Hi,

 

I am using GIT_COMMIT_GET function to get the commit date from Github history log. Unfortunately it is giving me a wrong date (10 years old) and when I look at the documentation, this function returns a time starting from 1970:

Time – the number of seconds since January 1st, 1970

 

As the SAS dates start from 01 Jan 1960, this is giving me a wrong date. Any idea how this can be fixed ?

 

%let GITBranch=Your_Local_Repository;

data work.x;
format time1 datetime.;
LENGTH COMMIT_ID AUTHOR_NAME AUTHOR_EMAIL MESSAGE PARENT_IDS TIME $ 1024;

N = GIT_COMMIT_LOG("&GITBranch.");

DO I=1 TO N;
RC = GIT_COMMIT_GET(I,"&GITBranch.", "id", COMMIT_ID);
RC = GIT_COMMIT_GET(I,"&GITBranch.", "author", AUTHOR_NAME);
RC = GIT_COMMIT_GET(I,"&GITBranch.", "email", AUTHOR_EMAIL);
RC = GIT_COMMIT_GET(I,"&GITBranch.", "message", MESSAGE);
RC = GIT_COMMIT_GET(I,"&GITBranch.", "parent_ids", PARENT_IDS);
RC = GIT_COMMIT_GET(I,"&GITBranch.", "time", TIME);
Time1=TIME;
output;
END;
RC = GIT_COMMIT_FREE("&GITBranch.");
drop N I RC;
run;

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
ChrisHemedinger
Community Manager

This is not unique to Git -- it's true for any time that you exchange date/time values with a system that uses epoch (Unix-style) times.

 

Here's an example for how to compensate.

 

options dlcreatedir;
%let repoPath = %sysfunc(getoption(WORK))/sas-dummy-blog;
libname repo "&repoPath.";
libname repo clear;
 
/* Fetch latest code from GitHub */
data _null_;
 rc = gitfn_clone(
   "https://github.com/sascommunities/sas-dummy-blog.git",
   "&repoPath.");
 put rc=;
run;

data commits (keep=time message);
  length time_char $ 100 time 8 message $ 100 n 8;
  n = gitfn_commit_log("&repoPath.");
  format time datetime20.;

  do i=1 to n;
    rc = gitfn_commit_get(i,"&repoPath.",'message',message);
    rc = gitfn_commit_get(i,"&repoPath.",'time',time_char);
    time = trim(time_char);
    time = time + "01jan1970 0:0:0"dt;
    output;
  end;
run;

title "Commits to this sas-dummy-blog repo";
proc print data=commits;
run;
title;
SAS For Dummies 3rd Edition! Check out the new edition, covering SAS 9.4, SAS Viya, and all of the modern ways to use SAS!

View solution in original post

4 REPLIES 4
Rick_SAS
SAS Super FREQ

Hmm, this is not a great solution, but you can manually subtract the number of seconds between 01JAN1970 and 01JAN1960 by using the INTCK function:

data A;
adjust = INTCK("seconds", '01JAN1960:00.00.00'dt, '01JAN1970:00.00.00'dt);
put adjust;
run;

The answer is 315,619,200 seconds, so you could adjust the TIME variable in your program by that amount.

Balli
Obsidian | Level 7
Thanks Rick 🙂
ChrisHemedinger
Community Manager

This is not unique to Git -- it's true for any time that you exchange date/time values with a system that uses epoch (Unix-style) times.

 

Here's an example for how to compensate.

 

options dlcreatedir;
%let repoPath = %sysfunc(getoption(WORK))/sas-dummy-blog;
libname repo "&repoPath.";
libname repo clear;
 
/* Fetch latest code from GitHub */
data _null_;
 rc = gitfn_clone(
   "https://github.com/sascommunities/sas-dummy-blog.git",
   "&repoPath.");
 put rc=;
run;

data commits (keep=time message);
  length time_char $ 100 time 8 message $ 100 n 8;
  n = gitfn_commit_log("&repoPath.");
  format time datetime20.;

  do i=1 to n;
    rc = gitfn_commit_get(i,"&repoPath.",'message',message);
    rc = gitfn_commit_get(i,"&repoPath.",'time',time_char);
    time = trim(time_char);
    time = time + "01jan1970 0:0:0"dt;
    output;
  end;
run;

title "Commits to this sas-dummy-blog repo";
proc print data=commits;
run;
title;
SAS For Dummies 3rd Edition! Check out the new edition, covering SAS 9.4, SAS Viya, and all of the modern ways to use SAS!
Balli
Obsidian | Level 7
Thanks Chris. It helps 🙂

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 2765 views
  • 2 likes
  • 3 in conversation