From owner-freebsd-questions Thu Feb 7 11:46:53 2002 Delivered-To: freebsd-questions@freebsd.org Received: from ralf.artlogix.com (sense-mcglk-240.oz.net [216.39.168.240]) by hub.freebsd.org (Postfix) with ESMTP id B858537B400 for ; Thu, 7 Feb 2002 11:46:46 -0800 (PST) Received: by ralf.artlogix.com (Postfix, from userid 1000) id 2C3981B9D0F; Thu, 7 Feb 2002 11:46:46 -0800 (PST) To: Brett Jackson Cc: questions@freebsd.org Subject: Re: using `date` in a script References: <20020207120404.O7616-100000@bsduser.ca> From: Ken McGlothlen Date: 07 Feb 2002 11:46:45 -0800 In-Reply-To: <20020207120404.O7616-100000@bsduser.ca> Message-ID: <873d0d5b2y.fsf@ralf.artlogix.com> Lines: 33 User-Agent: Gnus/5.0808 (Gnus v5.8.8) XEmacs/21.1 (Cuyahoga Valley) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG Brett Jackson writes: | I am having difficulty passing a variable to date(8) and have it spit out | the data in the date format. | | for example: | birthday=19450104 | | >date -f ccyymmdd $birthday | | that is some ugly psuedocode, eh? Can I even do this? Well, if I understand you correctly, you want to be able to pass in a date like "19450104" and be able to print out the date in its normal format. Yes? Well, for starters, you need the "-j" option. From the manpage: -j Do not try to set the date. This allows you to use the -f flag in addition to the + option to convert one date format to another. At this point, your script could read: #!/bin/sh BIRTHDAY=19450104 # Now print the date in standard Unix format. We need to add "0000" to # represent midnight on the given date. date -j ${BIRTHDAY}0000 The -f option isn't necessary in this case. To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message