dharmendrayadav
6th September 2016, 09:45
hi,

can anybody let me know how to get previous date from current date

like if today is 06-09-2016(dd-mm-yyyy) then i want 05-09-2016

BChary
6th September 2016, 10:07
long yesterday
yesterday = date.num() - 1
message(num.to.date$(yesterday,3))

date.num() give you date as number of days between 0001-01-01 and current day.

PS. i'm not sure, but i think you post in wrong thread.

dharmendrayadav
6th September 2016, 10:43
thanks its working but in need to take with time also can we do this with UTC date ??

My Code for current date with time:
cur.date = utc.num()


ret1 = utc.to.date(cur.date, curr.year, end.month, month_dayno, dummy, dummy, dummy)

adat.f = date.to.utc( curr.year, end.month, month_dayno, 00, 00, 00 )
adat.t = date.to.utc( curr.year, end.month, month_dayno, 23,59 , 59 )

i need same as above but for previous date

bhushanchanda
6th September 2016, 11:05
Hi,

You can use utc.add()

So, it should be something like this -

cur.date = utc.num()


ret1 = utc.to.date(cur.date, curr.year, end.month, month_dayno, dummy, dummy, dummy)

adat.f = date.to.utc( curr.year, end.month, month_dayno, 00, 00, 00 )
adat.t = date.to.utc( curr.year, end.month, month_dayno, 23,59 , 59 )

utc.add(adat.f, 0,0,-1, 0,0,0,prev.f)
utc.add(adat.t, 0,0,-1, 0,0,0,prev.t)

andreas.toepper
6th September 2016, 11:06
You can check if your LN Tools-set does support utc.add().

utc.add()
Syntax:
function long utc.add (long i.utc, long year, long month, long day, long hour, long minute, long second, long o.utc)

Description

This adds years, months, days, hours, minutes, seconds to the input utc value and makes corrections if necessary.

It processes the parameters from bigger to smaller units:

First adds only years and the date is corrected (if started from a leap year)
Than the months are added and the date is corrected to an existing one.
The addition of days follow, and the result is so far the same hour, minutes, as it was in the beginning in the actual time-zone.
Finally the hours, minutes, seconds are added.

If it does not support utc.add(), I think you will need to convert the utc date into local time first, subtract one day and reconvert into utc. This will be archived by using the functions:

- utc.to.local(..)
function long utc.to.local (long utc, ref long local_days, ref long local_time [, ref string local_dst])

- local.to.utc(..)
function long local.to.utc (long local_days, long local_time, ref long utc [, ref string local_dst])

dharmendrayadav
6th September 2016, 11:57
Thank you so much Bhushan, its fulfill my requirement, thanks to all for your kind help

saenzh
2nd October 2019, 00:10
I'm trying to do something similar to this but I'm trying to make my date field default to the 1st of the month every month. Ex. If this month is November I'd like my UTC date to be '01/11/2019 00:00:00'.

Is this possible?

Juergen
2nd October 2019, 09:55
Should be possible with something like this

domain tcdate first.of.act.month
long day, month, year

num.to.date (date.num(), year, month, day)
first.of.act.month = date.to.utc (year, month, 1, 0, 0, 0)

Regards,
Juergen

saenzh
2nd October 2019, 16:58
Thank you Juergen that worked!!!

I am also trying to do the same thing but I want to get the last day of the month. I would put 30 but some days are ending on 31. How can I get the last day of every month?

This is what I have below:



domain tcdate cfrm.date.to
num.to.date (date.num(), year, month, day)
cfrm.date.to = date.to.utc(year,month,30,0,0,0)

Juergen
2nd October 2019, 18:06
Easy solution could be

if month = 2 then
day = 28
else
if (month = 4 or
month = 6 or
month = 9 or
month = 11) then
day = 30
else
day = 31
endif
endif


Only problem with that simple calculation is the leap year which happens every four years and where the month of february has 29 days :)

saenzh
2nd October 2019, 19:01
That works! Thank you very much Juergen!

bdittmar
25th October 2019, 10:27
Hello,

or use : tccom.dll0350.get.last.day.of.month( long i.month, long i.year )


tccom.dll0350.get.last.day.of.month

long tccom.dll0350.get.last.day.of.month( long i.month, long i.year )

Expl. : Get the last day of the month for a given year.
Pre : i.month and i.year must be valid.
Post : -
Input : i.month - Month number, eg January = 1; February = 2...
i.year - Year.
Output : -
Return : Number of days in the month.

Also checking for leap year is:

tccom.dll0350.is.leap.year

boolean tccom.dll0350.is.leap.year( long i.year )

Expl. : The following algorithm is used to determine if a year is a
leap year.
1. The year is evenly divisible by 4 and
2. The year is not evenly divisible by 100,
3. Unless the year is evenly divisible by 400.
So, the years 1900 and 2100 are not leap years while
the year 2000 is a leap year.
Pre : -
Post : -
Input : i.year - Year.
Output : -
Return : True - Year is a leap year.
False - Otherwise.

Regards