gget79
17th April 2008, 18:52
Hi friends,
I am working with Baan IV C4.
I have a problem, I need to convert a date in date format to utc format, but I need something similar to this:
my.date = 01-01-2008
I need,
my.utc.1 = 01-01-2008 00:00:00 and,
my.utc.2 = 01-01-2008 23:59:59
I know that in Baan V, I do it with date.to.utc() function, but I have found in BaaNBoard and they suggest me to use *.num functions, but this doesn't resolve my problem, because I with *.num cannot put the time.
Any ideas?????
BaanInOhio
17th April 2008, 23:29
The 'utc' call in IV and V/LN have different arguments. The trick to making it work in IV is breaking the UTC (date+time field) unto two separate numbers = one containing the UTC date without time and the other with only the time. When set up this way, the utc to baan julian date conversion and time conversion from GMT to current time zone is done. Reversing this from date to UTC is probably similar. I haven't had to do it yet, but would guess that it would be similar to the example below:
utc.to.local(local.days, local.time, utc.days, utc.time)
All long variables. 'local.days', and 'local.time' are set by the function. The other two 'utc' fields must be filled before calling, containing the UTC number of days and time. The call in V/LN is a bit more straightforward and doesn't require this additional manipulation.
In the example below, I get a file's modification time from the OS, provided in UTC. This is converted to Baan julian date and time for display on a form:
declaration:
long local.time, f.size, f.mode, f.imode, f.dev, f.uid,
f.gid, f.nlink, f.ctime, f.mtime, f.atime, file.id
long local.days, utc.days, utc.time
| Get information about the file (already opened
| with 'seq.open', pointer = "file.id"). We
| only care about the create date, which is
| stated in a UTC format, seconds past
| 1/1/1900 00:00 GMT.
ret = fstat.info(file.id, f.size, f.mode, f.imode, f.dev, f.uid, f.gid,
f.nlink, f.ctime, f.mtime, f.atime)
| File modify time (f.mtime) is stated in
| number of seconds since 1/1/1970 00:00 UTC.
| Therefore, it must be converted to a number
| of days since 01/01/0001 (absolute UTC date)
| and seconds since midnight.
utc.days = f.mtime/86400
utc.time = f.mtime - (utc.days*86400)
utc.days = utc.days + date.to.num(1970,1,1)
| This call converts the separate UTC days
| and time fields to Baan julian date and
| time (seconds past midnight) fields.
ret = utc.to.local(local.days, local.time, utc.days, utc.time)
vahdani
18th April 2008, 10:28
Hi gget79,
here a simple function that I just put together to convert from local date and time to UTC:
function long local.to.utc(long i.date, long i.time, long gmt.diff.mins)
{
| gmt.diff.mins = Time Zone difference to GMT in minutes
domain tcdate utc.start
long days.since.utc.start
long utc.date
utc.start = date.to.num(1970, 1, 1)
days.since.utc.start = i.date - utc.start
if days.since.utc.start > 0 then
utc.date = (days.since.utc.start * 24 * 60 * 60)
+ (i.time - gmt.diff.mins * 60)
else
utc.date = -1
endif
return(utc.date)
}