Gossamer Forum
Home : Products : Others : Gossamer Community :

Date convert

(Page 1 of 2)
> >
Quote Reply
Date convert
Anyone with a quick Global for Date/Time for use in Communities (I prefer to set the format manually)

How can I convert the outout of:
<%Community::Web::Tools::convert_date($comm_created)%>

To %mmmm% %dddd% %yyyy% etc..


Klaus

http://www.ameinfo.com
Quote Reply
Re: [klauslovgreen] Date convert In reply to
Hi,

You could use GT::Date for this:

<%GT::Date::date_get($comm_created, "%mmmm% %dddd% %yyyy%")%>

Cheers,

Alex
--
Gossamer Threads Inc.
Quote Reply
Re: [Alex] Date convert In reply to
Thanks Alex,

How do I get current date and time (like the two globals in Links - they are not working as they are in Links)..

I used the below to get the date and time - but can't seem to format it the same way as you suggested earlier..?!?

sub {
my ($date) = scalar(localtime);
return $date;
}



Cheers
Klaus

http://www.ameinfo.com

Last edited by:

klauslovgreen: Jan 21, 2003, 12:27 PM
Quote Reply
Re: [klauslovgreen] Date convert In reply to
You could try:

<%GT::Date::date_get(0, "%mmmm% %dddd% %yyyy%")%>

to display the current time.

Cheers,

Alex
--
Gossamer Threads Inc.
Quote Reply
Re: [Alex] Date convert In reply to
Perfect!

Now if I wanted to show another time zone? Could I do that by adding +x or?

Thanks for your help
Klaus

http://www.ameinfo.com
Quote Reply
Re: [klauslovgreen] Date convert In reply to
You could check GT::Date documentation...

Best regards,
Webmaster33


Paid Support
from Webmaster33. Expert in Perl programming & Gossamer Threads applications. (click here for prices)
Webmaster33's products (upd.2004.09.26) | Private message | Contact me | Was my post helpful? Donate my help...
Quote Reply
Re: [webmaster33] Date convert In reply to
How can I translate months and days in my language? I must open GT libraries? What about the all translateable vars in gt apps? Unsure
Max
The one with Mac OS X Server 10.4 :)
Quote Reply
Re: [maxpico] Date convert In reply to
Well you can change date language texts in Admin config.

However you are right, the support for template based, full language support of date language texts is still MISSING. Frown
I would also welcome this improvement of GT::Date module... Not a big task, tough. I believe.

Best regards,
Webmaster33


Paid Support
from Webmaster33. Expert in Perl programming & Gossamer Threads applications. (click here for prices)
Webmaster33's products (upd.2004.09.26) | Private message | Contact me | Was my post helpful? Donate my help...
Quote Reply
Re: [webmaster33] Date convert In reply to
What do you mean by Admin config?
Max
The one with Mac OS X Server 10.4 :)
Quote Reply
Re: [maxpico] Date convert In reply to
Go Admin/Setup/Date Options.
There are Date text options: date_month_long, date_month_short, date_days_long, date_days_short

Unfortunately Date text options can not changed for each template, in language.txt.
This means if you have a Spanish, French, English templates, you can display your date texts in one language only, e.g in English.

Best regards,
Webmaster33


Paid Support
from Webmaster33. Expert in Perl programming & Gossamer Threads applications. (click here for prices)
Webmaster33's products (upd.2004.09.26) | Private message | Contact me | Was my post helpful? Donate my help...
Quote Reply
Re: [webmaster33] Date convert In reply to
I did read the documentation (perhaps I just did not understand what I was reading) - but I did not find a way to add/deduct hours - I can see how to show a date 7 days ago.. but not hours..

Anyway - I'll try to find a way.. thanks!

http://www.ameinfo.com
Quote Reply
Re: [klauslovgreen] Date convert In reply to
Is this what you were looking for?
From GT::Date docs: %o% + or - GMT offset

Hope this helps.

Best regards,
Webmaster33


Paid Support
from Webmaster33. Expert in Perl programming & Gossamer Threads applications. (click here for prices)
Webmaster33's products (upd.2004.09.26) | Private message | Contact me | Was my post helpful? Donate my help...
Quote Reply
Re: [webmaster33] Date convert In reply to
Yes I tried that and it show GMT -+ - but what I want is to add to the actual time displayed - not just get the GMT offset

Klaus

http://www.ameinfo.com
Quote Reply
Re: [klauslovgreen] Date convert In reply to
Probably the following function may help: date_transform ($date, $orig_fmt, $new_fmt);
And use the %o% in both formats.

I hope GT::Date can treat this conversion and will return the date in correct format...
Give it a try, you can't lose anything. Wink

I hope it will work.

Best regards,
Webmaster33


Paid Support
from Webmaster33. Expert in Perl programming & Gossamer Threads applications. (click here for prices)
Webmaster33's products (upd.2004.09.26) | Private message | Contact me | Was my post helpful? Donate my help...
Quote Reply
Re: [klauslovgreen] Date convert In reply to
If you can get the date into timestamp format, you can then calculate the number of seconds to add/subtract to find your new timezone...eg...

my $time = time; # GMT for me.

...New York is 5 hours behind so to find their time/date I'd do:

my $nyc = time - (60 * 60 * 5);

Then you can format the date as you wish.

Is that what you were looking for?
Quote Reply
Re: [Paul] Date convert In reply to
That's it!
Thanks Paul

Klaus

http://www.ameinfo.com
Quote Reply
Re: [klauslovgreen] Date convert In reply to
It's clear now, what you did need.
Paul gave you a correct solution.

As for the GT::Date module, I aggree, it would be fine to be able to do second, hour, month, year based operations, too, in addition to currently available day operations. Currently a possible workaround is, to convert a date to unix time, do operations, and convert back.

Following functions could be implemented:
- date_add_second, date_add_hour, date_add_month, date_add_year
- date_sub_second, date_sub_hour, date_sub_month, date_sub_year
- date_diff_second, date_diff_hour, date_diff_month, date_diff_year (e.g. result of date_diff_month will be a rounded month number)
Would not be too difficult to have these functions implemented.

Example for date_sub_hour function:
E.g.: $date = date_sub_hour ("2003-01-23 01:05:01 +0100", 3 ); # This would subtract 3 hour from date, and would result "2003-01-22 22:05:01 +0100".
Ok. These were my suggestions.

I also have a question, related to GMT dates. It's not clear how is possible to treat GMT based dates, using GT::Date functions. The docs unfortunately does not give examples about this.
I know & use several functions of GT::Date, but there are some undocumented features, and some are not documented well enough. I spent a few hours today to check how the features in GT::Date works, but GMT dates are not clear, yet.

Anybody has experience with GT::Date, in particular with GMT date usage?

Best regards,
Webmaster33


Paid Support
from Webmaster33. Expert in Perl programming & Gossamer Threads applications. (click here for prices)
Webmaster33's products (upd.2004.09.26) | Private message | Contact me | Was my post helpful? Donate my help...
Quote Reply
Re: [webmaster33] Date convert In reply to
Perhaps you'd care to show some example code of how you'd minus 3 hours from the following string...

Code:
2003-01-23 01:05:01 +0100

I wouldn't like to take the challenge Crazy

Last edited by:

Paul: Jan 22, 2003, 5:36 PM
Quote Reply
Re: [Paul] Date convert In reply to
Not sure what you want to say. Could you clarify?

Best regards,
Webmaster33


Paid Support
from Webmaster33. Expert in Perl programming & Gossamer Threads applications. (click here for prices)
Webmaster33's products (upd.2004.09.26) | Private message | Contact me | Was my post helpful? Donate my help...
Quote Reply
Re: [webmaster33] Date convert In reply to
Welp, you said...

Quote:
Would not be too difficult to have these functions implemented.

So I thought perhaps you could show some simple code that will do it.

Last edited by:

Paul: Jan 22, 2003, 5:44 PM
Quote Reply
Re: [Paul] Date convert In reply to
I will not post exact code right now, but I will show the logic how would I do it.
And of course I would also use existing GT::Date functions.
So, we have that date:
2003-01-23 01:05:01 +0100
And we want to subtract 3 hours, and display the result.

Solution A:
0) We input 2 values: a) date string b) output date format
1) Use parse_format - Takes a string and a date format and returns an array ref of the first 7 arguments returned by localtime().
We can use to have a date array.
Ok. we now have a date array.
2) We subtract 3 from 3rd array element (this is the hour).
3) if the array element would go below 0 because the subtract, we decrease the day, too. We have to take care of month, year changes if the subtract affects them.
So we have the correct date in the array.
4) Use format_date - Takes an array from localtime or equiv and a date format and returns date.
We can use that function to convert date array to formatted date. We use the second input value if it was given.
5) return result date


Solution B:
0) We input 2 values: a) date string b) output date format
1) Use _date_str_to_time - Takes a date string and converts it to a unix time.
Ok. We now have the date in unix time.
2) We subtract 60 * 60 * 3 from the unix time.
3) Use date_get - Return today's date or a date from a time() that you pass in.
So we use the second feature, that we give input, and we get output in date string format
4) return result date


I gave you 2 solutions. The second is the best of them.
Was that difficult?

Best regards,
Webmaster33


Paid Support
from Webmaster33. Expert in Perl programming & Gossamer Threads applications. (click here for prices)
Webmaster33's products (upd.2004.09.26) | Private message | Contact me | Was my post helpful? Donate my help...
Quote Reply
Re: [webmaster33] Date convert In reply to
Quote:
Was that difficult?

An explanation is not difficult of course :)
Quote Reply
Re: [Paul] Date convert In reply to
Would you mean to insinuate that I could not program it?

Best regards,
Webmaster33


Paid Support
from Webmaster33. Expert in Perl programming & Gossamer Threads applications. (click here for prices)
Webmaster33's products (upd.2004.09.26) | Private message | Contact me | Was my post helpful? Donate my help...
Quote Reply
Re: [webmaster33] Date convert In reply to
In post 18 I said:

Quote:
I wouldn't like to take the challenge

My point is that you said it wasn't too difficult and so I thought perhaps you could show us how it was done. I've never seen you post any code so I was trying to encourage you to do so to see what solution you came up with.

To modify a date string is really not that easy at all (without using a pre-made module) so by asking you to write some code I thought perhaps I could make you realise that without saying outright.

However you didn't take the challenge :)
Quote Reply
Re: [Paul] Date convert In reply to
Paul,
Of course I will not take the challenge, because
1) I have a lot other things to work on
2) It's not my job to do improvements on the GT::Date. I gave the suggestions & for your request I gave the synopse how can be done
3) I wrote a script for date format change (convert_date.pl) 3 years ago, does the same what GT::Date does. My script does not know so much, as GT::Date, is not module based, but converts dates correctly from any format to any format, to unix time and from unix time back to chosen format, also can display date languages in many language, including Hungarian, German, English, French, Russian, Spanish, and probably more automatically, just by setting the correct locale.
convert_date.pl v1.00 (was finished on 03.01.2000)
convert_date.pl v2.0beta3 (the last version was modified on 07.30.2001)


So I don't want, don't need, and don't have to prove anything about my programming knowledge, especially not for you.
I'm not professional perl programmer, and probably I don't know so much like a professional, because I don't program perl in full time. It's my hobby.
But I refuse your doubt about my programming knowledge!!!

Are you provocative, aren't you?

Best regards,
Webmaster33


Paid Support
from Webmaster33. Expert in Perl programming & Gossamer Threads applications. (click here for prices)
Webmaster33's products (upd.2004.09.26) | Private message | Contact me | Was my post helpful? Donate my help...
> >