Operating System - HP-UX
1827354 Members
5780 Online
109963 Solutions
New Discussion

URGENT HELP REQUIRED on DATE to add 1 or more days getting error date when BST to GMT time conversio

 
SOLVED
Go to solution
Satish Kumar Malisetti
Frequent Advisor

URGENT HELP REQUIRED on DATE to add 1 or more days getting error date when BST to GMT time conversio

Hello ALL,

I have a written a script ,
which converts currenr date into epoch seconds
and add number of days (ex: 1 ,2,3)
multilpy the days*86400 seconds
convert that seconds into date

every day i am adding 1 or 2 days depending on the requirement to the current date

but this is not adding one day when the time zone is from BST to GMT as 1 hour reduces

for that i have written only for that particular day if the passed date and coneverted date are same then add 25 hours for that particular day

but when i am passing days to add while converting from BST to GMT i am getting only one day is adding
15 REPLIES 15
Horia Chirculescu
Honored Contributor

Re: URGENT HELP REQUIRED on DATE to add 1 or more days getting error date when BST to GMT time conversio

Hello,
Please check on this thread:

http://forums11.itrc.hp.com/service/forums/questionanswer.do?threadId=1411389

The perl script that James has posted. There is also an older thread listed there.

strftime just converts the seconds into a desired format.

Horia.
Best regards from Romania,
Horia.
Matti_Kurkela
Honored Contributor

Re: URGENT HELP REQUIRED on DATE to add 1 or more days getting error date when BST to GMT time conversio

So the date should be increased by N days, but the (local timezone) time should stay the same, right?

How about if you just do the calculation like you do now, but then overwrite the hour/minute/second part of the answer with the hour/minute/second of the original date?

MK

MK
Laurent Menase
Honored Contributor

Re: URGENT HELP REQUIRED on DATE to add 1 or more days getting error date when BST to GMT time conversio

Matti, may be there would be an error at dst change time...


Else if you share your script which makes that, and an example, it may be more easy to help you.
Satish Kumar Malisetti
Frequent Advisor

Re: URGENT HELP REQUIRED on DATE to add 1 or more days getting error date when BST to GMT time conversio

Laurent Menase ,


script and eaxmple given below

proc Lb_AddDaysToDateWithoutTime { pm_current_date pm_days }{


set lv_epochCurrentDate [mktime $pm_current_date ]
local lv_futureSec [expr $pm_days * 86400]
local lv_futureAdd [expr $lv_epochCurrentDate + $lv_futureSec]
local lv_futureConvert [date $lv_futureAdd]
return $lv_futureConvert
}

example :

dsd >puts [Lb_AddDaysToDateWithoutTime 20101031 1]
answer : 20101031

dsd >puts [Lb_AddDaysToDateWithoutTime 20101030 1]

answer : 20101031


Please look into above example, now the time zone is GMT0BST
same script is working fine when time zone is GMT




Laurent Menase
Honored Contributor
Solution

Re: URGENT HELP REQUIRED on DATE to add 1 or more days getting error date when BST to GMT time conversio

It is because of 20101031 is the dst change date, so the day last 1 hour more,

Since you calculate the date at 0:0:0 when you add 86400sec, you will be on the same day at 11pm

So workarounds: make the calculation at midday (12:00:00)
Laurent Menase
Honored Contributor

Re: URGENT HELP REQUIRED on DATE to add 1 or more days getting error date when BST to GMT time conversio

other workaround, add 43200 to the date

local lv_futureSec [expr $pm_days * 86400 + 43200]


Satish Kumar Malisetti
Frequent Advisor

Re: URGENT HELP REQUIRED on DATE to add 1 or more days getting error date when BST to GMT time conversio

thanks alot it working fine

but i need to check with the design team whether we can take midday timeor not
Laurent Menase
Honored Contributor

Re: URGENT HELP REQUIRED on DATE to add 1 or more days getting error date when BST to GMT time conversio

+ 43200 is changing exactly the time to midday :D
Dennis Handly
Acclaimed Contributor

Re: URGENT HELP REQUIRED on DATE to add 1 or more days getting error date when BST to GMT time conversio

If this uses the C mktime(3) then there is a tm_isdst field that indicates if DST is in effect. If this value changes from the start to the end date, you know you have to adjust your hour and possibly minute fields.
Satish Kumar Malisetti
Frequent Advisor

Re: URGENT HELP REQUIRED on DATE to add 1 or more days getting error date when BST to GMT time conversio

Dennis,

i didn't get you , could you please expalin me bit more

thanks in advance
Dennis Handly
Acclaimed Contributor

Re: URGENT HELP REQUIRED on DATE to add 1 or more days getting error date when BST to GMT time conversio

>could you please explain me bit more

What is the value of tm_isdst before you increment days? What is the value after?
After you call mktime(3), all of the values are adjusted to the correct/canonical local time.
James R. Ferguson
Acclaimed Contributor

Re: URGENT HELP REQUIRED on DATE to add 1 or more days getting error date when BST to GMT time conversio

Hi:

Perl leverages the standard libc routines in an easy-to-use fashion, so why reinvent the wheel?

# perl -MPOSIX -le '$t=shift||0;print strftime "%Y/%02m/%02d %02H:%02M:%02S %Z %z",localtime(time+($t*(60*60*24)))' 1

...will yield tomorrow's date and time in your localtime. For me, this would look like:

2010/03/15 10:08:41 EDT -0400

...which shows that I am in Eastern Daylight Time, 4-hours behind from UTC/GMT.

You can use the script above to go backwards in time by doing:

# perl -MPOSIX -le '$t=shift||0;print strftime "%Y/%02m/%02d %02H:%02M:%02S %Z %z",localtime(time+($t*(60*60*24)))' -- -2

2010/03/13 09:13:21 EST -0500

...which shows that I just crossed a Daylight Saving Time boundry yesterday morning.

Regards!

...JRF...

You can use the formatting directives of 'strftime' which parallel those for the standard 'date' command
Dennis Handly
Acclaimed Contributor

Re: URGENT HELP REQUIRED on DATE to add 1 or more days getting error date when BST to GMT time conversio

>JRF: Perl leverages the standard libc routines in an easy-to-use fashion, so why reinvent the wheel?

That's what I've been saying. :-)

It appears that Satish wants to know when incrementing by N days doesn't give the same time of the day.

I suggested that he look at the tm_isdst field after calling mktime(3).

>2010/03/15 10:08:41 EDT -0400
>2010/03/13 09:13:21 EST -0500

Satish doesn't seem to want that. (That "add 25 hours" comment.)
Satish Kumar Malisetti
Frequent Advisor

Re: URGENT HELP REQUIRED on DATE to add 1 or more days getting error date when BST to GMT time conversio

NOW MY QUERY IS RESOLVED THROUGH ADDING 12 HOURS (MID-DAY)

THANKS ALOT
Laurent Menase
Honored Contributor

Re: URGENT HELP REQUIRED on DATE to add 1 or more days getting error date when BST to GMT time conversio

Even if we don't do it for that, it is usually nice to give points before close. And it is also better as it indicates that the subject was solved.