StrToTime Returns 00 for secs

 

Hello everyone,

I have this weird issue when reconstructing a date it is showing the seconds 00. Sometimes it doesnt do that and shows it properly. I honestly have no idea why its working and not working but here is my code.

datetime DateRecon=TimeLocal();
int year,day,month,hour;
year = TimeYear(DateRecon);
day = TimeDay(DateRecon);
month = TimeMonth(DateRecon);
hour = TimeHour(DateRecon);

DateRecon=StrToTime(year+"."+month+"."+day+" "+hour+":"+result[0]+":"+result[1]);

Comment(DateRecon);

The output works to the min. Except the Secs shows 00. And sometimes it works. It's like it decides when to work and when not to work.

Any advice on this matter would be highly appreciated.

Thank you,

P.s. Even if I replace result[1] with a number it still shows secs as :00

 

Do you really expect an answer? There are no mind readers here and our crystal balls are cracked. Always post all relevant code (using Code button) or attach the file.
     How To Ask Questions The Smart Way. (2004)
          Be precise and informative about your problem

We have no idea what result[0] and result[1] are.

 
William Roeder #:

Do you really expect an answer? There are no mind readers here and our crystal balls are cracked. Always post all relevant code (using Code button) or attach the file.
     How To Ask Questions The Smart Way. (2004)
          Be precise and informative about your problem

We have no idea what result[0] and result[1] are.

Hey William,

Let me post the full code

datetime DateRecon=TimeLocal();
int year,day,month,hour;
year = TimeYear(DateRecon);
day = TimeDay(DateRecon);
month = TimeMonth(DateRecon);
hour = TimeHour(DateRecon);

DateRecon=StrToTime(year+"."+month+"."+day+" "+hour+":"+05+":"+55);

Comment(DateRecon);

I get

2021.11.30 18:05:00

Like I said the seconds is always 00

I dont understand why.

Hope you can help!

Thanks!

 

Audai Louri #:

2021.11.30 18:05:00

Because StrToTime always returns "yyyy.mm.dd hh:mi". No seconds.

Try the following;

DateRecon = StrToTime((string)year + "." + (string)month + "." + (string)day + " " + (string)hour + ":" + (string)05);

Comment(TimeToStr(DateRecon + 55, TIME_DATE|TIME_SECONDS));



 
Nagisa Unada #:

Because StrToTime always returns "yyyy.mm.dd hh:mi". No seconds.

Try the following;



That was the problem.

Thank you so much Nagisa you are truly a helpful person.

Wish there was a voting system on these forums so I can vote you up!

 
Nagisa Unada #:

Because StrToTime always returns "yyyy.mm.dd hh:mi". No seconds.

Try the following;

This is incorrect, while documentation says the input format is "yyyy.mm.dd hh:mi" , but it returns the seconds as well. The problem is in the formatting as one digit numbers are converted to one character text, so if the minute is 5, the string will be "18:5:55". Try formatting your string correctly or you will get same problems in converting month, day and hour as well.

 
Mohammad Hossein Sadeghi #:

This is incorrect, while documentation says the input format is "yyyy.mm.dd hh:mi" , but it returns the seconds as well. The problem is in the formatting as one digit numbers are converted to one character text, so if the minute is 5, the string will be "18:5:55". Try formatting your string correctly or you will get same problems in converting month, day and hour as well.

Oh, yes, indeed.

I misunderstood the output format as "yyyy.mm.dd hh:mi".

The reason is that he did not convert int to string in the original program.

DateRecon=StrToTime(year+"."+month+"."+day+" "+hour+":"+05+":"+55);

Reason: