Click here to Skip to main content
15,885,914 members
Please Sign up or sign in to vote.
3.50/5 (2 votes)
See more:
Hi All,

In csv file, there is a string value(date)that appears as: 00:55.0 , but when clicked on that, 21:00:55 appears in the formula bar.

When I try to extract the value, the code :

C++
wchar_t *pStrTime    =  str3; // this variable holds the time value  


When I run my program in debug, to check the values, this pStrTime takes 21:00:55, but when I print this using :

C++
wchar_t *pStrTime    =  str3; // this variable holds the time value  str.Format(_T("%s),pstrTime)


But when I print it, 00:55.0 is printed.

Why is that?
Posted
Updated 14-Jun-12 0:47am
v2
Comments
Richard MacCutchan 14-Jun-12 6:06am    
How are you getting the value from the Excel worksheet?
Sumal.V 14-Jun-12 6:11am    
Using swscanf_s function.

1 solution

If you're reading it with swscanf_s function, I'm going to guess that it really isn't an Excel file - perhaps a csv file (that will open in Excel by default).

As for the display in Excel showing 00:55.0 and the value appearing to be 21:00:55, you need to be aware that Excel attempts to be "smart" about reading your data. That is to say it attempts to format the data in a way that Excel thinks it should be - which is not always right.

If you click on that cell and format it with a custom format you will see different displays. For instance, that particular data appears to be a date/time, but also perhaps with milliseconds included, so set the custom format to "hh:mm:ss.000" (without the quotes) and you'll see something like 21:55:00.000 in Excel.

Hope this helps.
 
Share this answer
 
Comments
Sumal.V 14-Jun-12 6:46am    
Oops sorry, yeah. It is a csv file that opens in excel.
Yeah if I change that myself in excel it does change the format and display the desired values. :)

Cheers
Sumal.V 14-Jun-12 6:46am    
Will update my question.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900