Jump to content
dandantas

somar dias a data tipo time_t

Recommended Posts

dandantas

boas meus caros

ando aqui a matutar num problema

ora vejamos:

pretendo adicionar um numero de dias a uma data que esta numa estrutura, o tipo de dados é time_t.

time_t hoje, data; //data valor na estrutura e é referente ao passado superior a 90 dias

time(&hoje);

data=data-((hoje-data)/86400-90);

//desta forma pretendo que variavel data fique com o valor data de 90 dias atras.

da para ajudar...é que ja andei aos tombos com isto =)

Share this post


Link to post
Share on other sites
KTachyon
time_t hoje, data;
time(&hoje);
data = hoje - 90*24*60*60;


“There are two ways of constructing a software design: One way is to make it so simple that there are obviously no deficiencies, and the other way is to make it so complicated that there are no obvious deficiencies. The first method is far more difficult.”

-- Tony Hoare

Share this post


Link to post
Share on other sites
bubulindo

time_t não é uma estrutura se me lembro correctamente.

data = hoje - (86400 * 90); //86400 segundos por dia, vezes 90 dias... se alterares o sinal passa para o futuro. 

Não é algo assim que procuras?


include <ai se te avio>

Mãe () {

}

Share this post


Link to post
Share on other sites
KTachyon

time_t não é uma estrutura se me lembro correctamente.

Exacto, um time_t é um long int disfarçado.


“There are two ways of constructing a software design: One way is to make it so simple that there are obviously no deficiencies, and the other way is to make it so complicated that there are no obvious deficiencies. The first method is far more difficult.”

-- Tony Hoare

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.