cancel
Showing results for 
Search instead for 
Did you mean: 

Converting date on GPS ?

antonius
Senior

Dear Members,

How can I convert date on GPS ?

UTC date 60819

into

6-August-2019 ?

thanks

15 REPLIES 15

Couldn't you divide by 100 and 10000 to extract the DD, MM and YY fields, and add 1900 or 2000 depending if YY is below 80

​

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
antonius
Senior

correct me ?

   day = date/10000;

         month = date/100-(day*100);

         year = date/100-((day*100)+month);

int day,month,year;
 
         day = date/10000;
 
         month = date/100-(day*100);
 
         year = date/100-((day*100)+month);
 
       printf("======================GPRMC PARSING =================\r\n");
 
         printf("UTC date %x \r\n",date);
 
         printf("Day %u-",day);
 
         printf("Month %u-",month);
 
         printf("Year %u-",year);
 
         printf("\r\n");
 
         printf("====================== D O N E !=================\r\n");

am I right ?

Thanks

>> am I right ? correct me ?

Put the code in a function, and run test cases against it.

The year computation is broken

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

thanks for the response,

what do I miss on year computation ?

thanks

UTC date 60819

Day 6 Month 8 Year 19

UTC date 60180

Day 6 Month 1 Year 80

UTC date 310517

Day 31 Month 5 Year 17

UTC date 60819

Day 6 Month 8 Year 2019

UTC date 60180

Day 6 Month 1 Year 1980

UTC date 310517

Day 31 Month 5 Year 2017

#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
 
void test1(int date)
{
  int day, month, year;
 
  printf("UTC date %6d \r\n",date);
 
  day = date/10000;
 
  month = (date - (day*10000)) / 100;
 
  year = date - (((day*100) + month) * 100);
 
  printf("Day %2d Month %2d Year %2d\n",day, month, year);
}
 
void test2(int date)
{
  int day, month, year;
 
  printf("UTC date %6d \r\n",date);
 
  day = date / 10000;
 
  date = date % 10000;
 
  month = date / 100;
 
  year = date % 100;
 
  if (year < 80) year += 2000; else year += 1900;
 
  printf("Day %2d Month %2d Year %4d\n",day, month, year);
}
 
int main(int argc, char **argv)
{
  test1(60819);
  test1(60180);
  test1(310517);
  putchar('\n');
 
  test2(60819);
  test2(60180);
  test2(310517);
  putchar('\n');
 
  return(1);
}

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

Thanks Clive, I will test it and keep posted, thank you...

I got output :

UTC date 1050649 
                                                             
Day 105 Month  6 Year 2049
   

for input 100819

 sscanf(field[9],"%x",&date); // UTC date

         test1(date);

         test2(date);