Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Change Date Format 1

Status
Not open for further replies.

clkaren

MIS
Sep 3, 2001
10
0
0
SG
Hi all,

Please advise if anyone know how to change date format in Solaris to dd/mm/yy and save the changes permanently.

Thanks
Karen
 
the get this format do the command :
date +%d/%m/%y

I am not sure of what you mean by change the format permanently.

you can make an alias for date in your .profile or .login to get this format whenever you type date.
 
Hi,

I have used the above date format to get the format but
when I try to issue the date command again, it's using
the default setting again.
Can you advise me how to make use of alias to add in the date format in the .login and .profile.

Thanks
Karen
 
You cant make a permenant change to the date format, but you create an alias e.g.

alias mydate date +%d/%m/%y

now if you type mydate you will always get the format as above. To retain this, you need to add the alias line to your .profile or .login or .cshrc then when you login it will be set again.
 
I'm not sure if it's possible to change the date format permanently or not, though no doubt someone here will know whether it is. I think the basic difficulty lies in the Solaris date including a time element. Bearing in mind that cron and other scheduled tasks depend on the date and time, I wonder whether it's worth tinkering with it with the possibility that something might go kaput as a result. Just a thought.
 
Default date format (and others), are setting in locale environment, you can verify this with "locale":
# locale
LANG=C
LC_CTYPE="C"
LC_NUMERIC="C"
LC_TIME="C"
LC_COLLATE="C"
LC_MONETARY="C"
LC_MESSAGES="C"
LC_ALL=

the LC_TIME environment var controls most default's of date/time commands, you can check default date format with:
# locale d_t_fmt
%a %b %d %H:%M:%S %Z %Y
you can check that is true by doing some checks:
# date
Thu Sep 06 00:59:10 WEST 2001
date +"%a %b %d %H:%M:%S %Z %Y"
Thu Sep 06 01:00:48 WEST 2001

you can also verify all defaults for LC_TIME with "locale LC_TIME", and all defaults with "locale LC_ALL"

so if you want to change default format of date you can change the value of LC_TIME to a locale that holds your required format,i.e, you can check if POSIX holds the default value you want by:
# LC_ALL=POSIX locale -ck d_t_fmt
LC_TIME
d_t_fmt="%a %b %d %H:%M:%S %Y"

if none of present locales will handle your format you can always build a locale for you with all the formats you want, solaris provide a source file of locale:
"/usr/lib/localedef/src/iso_8859_1" that you can change to build your own locale, change it and just compile it with "localedef",i.e, if you locale is "mylocale":
# cd /usr/lib/localedef/src
# mkdir mylocale
# cp iso_8859_1/* ./mylocale
# cd mylocale
... change files ...and compile ..
# localedef -v -i localedef.src -f charmap.src -x extension.src mylocale

then
# export LC_ALL=mylocale

Hope it helps,

Regards,

Carlos Almeida,














 
Hi cfsalmeida,

I have try the steps that you provided but I encountered
syntax error when compile.
Are you able to advise.

I have added in the following into the localedef.src in the mylocale directory.

=========================
LC_TIME

d_t_fmt="%a %b %d"

END LC_TIME
=========================


=========================================================
Error Message
--------------

localedef -v -i localedef.src -f charmap.src -x extension.src mylocale
localedef [ERROR]: FILE: localedef.src, LINE: 9, CHAR: 9
Syntax Error.
==========================================================

Thanks & Regards
Karen
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top