Extract a date from a sentence

I want to extract the date (dd/mm/yy) from a NMEA gps phrase.
It looks like this:
Here the date is November 19, 1994.

I could do by counting where to take the digits but I would prefer, to be sure of the reliability of the result, to position myself after the 9th comma (where the date begins) then extract these 6 digits.
But how to do this in Arduino code?

Link to inquire about GPRMC sentence: GPRMC

strtok is the word your google for.

1 Like

Thank you very much !
It works very well and it's simple.

Is there a way to do it cleaner or with less code even if it's already not bad?

void setup(void) {
  char *token;
  char *mystring = "$GPRMC,225446,A,4916.45,N,12311.12,W,000.5,054.7,191194,020.3,E68*";
  const char *delimiter = ",";


  int t = 0;

  token = strtok(mystring, delimiter);

  while (!(t == 9)) {
    token = strtok(NULL, delimiter);


void loop(void) {

1 Like

If you use a library like TinyGPS++, dates and everything else of interest is extracted automatically.

1 Like

I would use one of the GPS libraries. My favorite is TinyGPS++ (a.k.a. TinyGPSPlus). There are also TinyGPS and Adafruit_GPS_Library.

For now the NMEA sentence was enough for me (perfect to be converted into gpx) so I didn't need a library.
I may use this library to improve my project.

But sometimes it might be better to do the code yourself and figure it out?

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.