LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 01-26-2004, 11:15 AM   #1
aadaileh
LQ Newbie
 
Registered: Jan 2004
Location: Germany
Posts: 9

Rep: Reputation: 0
How to get the month in one digit instead of two digits in the "date" command?


Hi there ...

I am having problem with generating the following date format using the 'date command' in FreeBSD: 2004-1-26

The problem that I am getting the date written in this way: 2004-01-26

All I need is getting red of the zero which stands in fron of the month.

Thanx a lot,
Ahmed
 
Old 01-26-2004, 11:20 AM   #2
aadaileh
LQ Newbie
 
Registered: Jan 2004
Location: Germany
Posts: 9

Original Poster
Rep: Reputation: 0
Sorry ... I forgot the code I use ...

date '+%Y-%m-%d'

Thanx,
Ahmed
 
Old 01-26-2004, 11:23 AM   #3
jtshaw
Senior Member
 
Registered: Nov 2000
Location: Seattle, WA USA
Distribution: Ubuntu @ Home, RHEL @ Work
Posts: 3,892
Blog Entries: 1

Rep: Reputation: 66
date +%Y-%-m-%-e
 
Old 01-28-2004, 02:58 AM   #4
aadaileh
LQ Newbie
 
Registered: Jan 2004
Location: Germany
Posts: 9

Original Poster
Rep: Reputation: 0
Thanx a lot for your response, but it seems that we have a missunderstanding here

What I wanted to have is a "month" without leading zero not day.


The command "date +%Y-%m-%e" gives back the days without leading zero.


Thanx,
Ahmed
 
Old 01-28-2004, 07:56 AM   #5
jtshaw
Senior Member
 
Registered: Nov 2000
Location: Seattle, WA USA
Distribution: Ubuntu @ Home, RHEL @ Work
Posts: 3,892
Blog Entries: 1

Rep: Reputation: 66
Ok, I took the leading 0 out of both. %m = month, %-m = month without leading zero. For some reason you took out the - I had inserted after the %.


Use this command exactly as I have written it and only the month will lose the leading 0:
date +%Y-%-m-%d

Last edited by jtshaw; 01-28-2004 at 07:59 AM.
 
Old 01-28-2004, 08:17 AM   #6
aadaileh
LQ Newbie
 
Registered: Jan 2004
Location: Germany
Posts: 9

Original Poster
Rep: Reputation: 0
Thanx again...

It works

Regards,
 
Old 02-05-2004, 03:33 AM   #7
aadaileh
LQ Newbie
 
Registered: Jan 2004
Location: Germany
Posts: 9

Original Poster
Rep: Reputation: 0
Hi again,

The command [date +%Y-%-m-%d] generates the desired format (I mean without the leading zero) in Linux-SuSe not in FreeBSD

When I run it in FreeBSD it gives back the following output:

prompt@user :/usr/local/etc > date +%Y-%-m-%d
2004--m-05
prompt@user :/usr/local/etc > date +%Y-%-m-%e
2004--m- 5

Do you have any idea to handle this problem?

Regards,
Ahmed
 
Old 02-05-2004, 04:57 PM   #8
artur
Member
 
Registered: Apr 2002
Location: Illinois, US
Distribution: Red Hat, Fedora, Yellow Dog, Debian, FreeBSD, Embedix
Posts: 106

Rep: Reputation: 15
In case you can't get it worked out with just date '+%Y-%m-%d'
, try:
Code:
date '+%Y-%m-%d' | sed -e 's/-0/-/g'
You can omit the "g" if you only want the first leading 0 omitted
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Shell Script: Find "Word" Run "Command" granatica Linux - Software 5 07-25-2007 07:42 AM
cdrecord command-line parentheses "(" ")" coolingtower Linux - Software 1 10-28-2005 11:49 AM
Tiny Sofa 2.0 - I thought "halt", "reboot" were only root command ?? sorcerer Linux - Distributions 1 08-21-2004 03:28 PM
"segmentation error" when issuing "useradd" command through terminal with RH 9.0 kaihuang Linux - General 0 10-21-2003 11:47 PM
Monthly Archiving Script... help with "date" & "cron" Supp0rtLinux Linux - Software 3 01-03-2003 09:29 PM


All times are GMT -5. The time now is 12:33 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration