Question: I have been looking around to get what I want but I couldn't find anything hence my question (hopefully not a duplicate!)

I am looking to get a microsecond resolution epoch time (to be converted to a Date string) of the clock perhaps using `chrono`.

Following is what works for me for `seconds` resolution:

```
auto secondsEpochTime = std::chrono::duration_cast<std::chrono::seconds>(std::chrono::system_clock::now().time_since_epoch()).count();
std::cout << "Date string = " << ctime(&secondsEpochTime);

```

However when I change `seconds` to `microseconds`, `ctime` doesn't seem to reflect the correct date.

```
auto microSecondsEpochTime = std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::system_clock::now().time_since_epoch()).count();
std::cout << "Date string = " << ctime(&microSecondsEpochTime); // incorrect Date

```

Answer: 
The referenced column in a foreign key needs to be indexed, so you need to add an index on the `idEtape` column in `etapexprojet`:

```
--Etape X Projet
CREATE TABLE IF NOT EXISTS jegere.EtapexProjet_ (
    idEtape INT NOT NULL,
    idProjet INT NOT NULL,
    dateDebut DATE NOT NULL ,
    dateFin DATE,
    PRIMARY KEY(idProjet, idEtape),
    INDEX (idEtape),
    FOREIGN KEY(idProjet) REFERENCES projet_(idProjet)
);

```

Having it as part of the primary key isn't sufficient. A prefix of an index is also an index, but `idEtape` is a later part of the primary key index, so it's not indexed by itself.

Another solution is to change the order of the primary key:

```
    PRIMARY KEY(idEtape, idProject),

```
Your last table etape references only the column idetape, but all referenced columns need an index , primary key or UNIQUE constraint.

so add a KEY to your EtapexProjet\_ for the column idetape, and you can run the code

```
CREATE TABLE IF NOT EXISTS EtapexProjet_ (
    idEtape INT NOT NULL,
    idProjet INT NOT NULL,
    dateDebut DATE NOT NULL ,
    dateFin DATE,
    PRIMARY KEY(idProjet, idEtape),
    KEY(idEtape),
    FOREIGN KEY(idProjet) REFERENCES Projet_(idProjet)
);

```

see <https://dbfiddle.uk/z9QFoH0c>