I made a function that would allow me to get the current date and put it on a string in YYYY.MM.DD format.

string Date::getCurrentDate(){
char datenew[8];
char currentdate[8];
string s;
int size;
_strdate(datenew);
 
            currentdate[0]=datenew[6];
            currentdate[1]=datenew[7];
            currentdate[2]=datenew[5];
            currentdate[3]=datenew[0];
            currentdate[4]=datenew[1];
            currentdate[5]=datenew[2];
            currentdate[6]=datenew[3];
            currentdate[7]=datenew[4];
 
            size=sizeof(currentdate);
            s.assign(currentdate,size);
            return s;    
}

I keep getting a datenew is corrupted error. Why does this happen?

Well according to this the buffer needs to be 9 bytes long. Try changing datenew[8] to datenew[9] .

commented: Helpful +2
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.