Sponsored Content
Top Forums Programming C Calender Help - Unusual error Post 302112182 by jim mcnamara on Monday 26th of March 2007 11:35:01 AM
Old 03-26-2007
FWIW - consider the C standard library for most of what you're doing.
Code:
#include <time.h>
#include <stdio.h>

char *setday1(char *month, char *year, struct tm *input)
{
	struct tm *retval=NULL;
	char tmp[80]={0x0};
	
	sprintf(tmp,"01-%s-%s", month, year);
	if(strptime(tmp,"%d-%m-%Y", input) == NULL) /* format for dd-mm-yyyy */
		return NULL;
	return month;
}

int main(int argc, char **argv)
{
	struct tm working;
	char date[80]={0x0};

	if( setday1(argv[1], argv[2], &working)!=NULL)	
		strftime(date, 80, "%A, %B %d, %Y", &working);		
	else
	{
		fprintf(stderr, "Bad date\n");
		return 1;
	}
	printf("First day of the month: %s\n", date);	
	return 0;
}

man mktime
man strptime
man strftime
 

10 More Discussions You Might Find Interesting

1. Solaris

Unusual error : KEY in LOCKED position ignoring debug enter sequence

Hi, This was very unusual situation I never came across & we have SUN engineers working on this. We have Sun Fire V240 Server, 2 1.5-GHz UltraSPARC IIIi CPU, Solaris 9 Installed During the boot-up it gives following message, <date> <server name> unix : KEY in LOCKED position ignoring... (5 Replies)
Discussion started by: sacrh
5 Replies

2. Shell Programming and Scripting

Getting unusual error - moving files to another directory

Dear experts, Im having an unusual problem and its been giving me a bad headache. I have the script below #!/usr/bin/sh -x ticketinputdir=/IN_DATA1/tickets ticketoutputdir=/IN_DATA2 YDAY=`env TZ=A12B date '+%Y%m%d'` for i in INA INB INC IND INE do mkdir $ticketoutputdir/$i/$YDAY... (4 Replies)
Discussion started by: aismann
4 Replies

3. Shell Programming and Scripting

Calender Unix programming date issues

Hi, i;m beginner of Unix, i trying to use crontab to zip my log file automatically, below is my coding, some of the statement i don't know whether is correct or not. Pls help:) year=`date '+%Y'` month=`date '+%m'` day=`date '+%d'` day=`expr $day - 1` case $month in 1 | 3 | 5 | 7 | 8 | 9 |... (4 Replies)
Discussion started by: dannyd_y
4 Replies

4. Fedora

Script to find out first day of our calender

I try to find the first day of our calender. So I used this script ... echo -n "The week of the date 01jan0001 : " echo -n `date -d 00010101 +%A` echo But its shows error bash-3.1$ sh first_day.shThe week of the date 01jan0001 : date: invalid date `00010101' (3 Replies)
Discussion started by: krishnampkkm
3 Replies

5. Shell Programming and Scripting

Question on Autosys calender date.

Hi I am trying to schedule a job through Autosys through UNIX on a particular day of every month (for example 20th of every month). Can some one please help me whats the command or whats the process to run on that particular day of month. Thank you, (2 Replies)
Discussion started by: sravuri
2 Replies

6. UNIX Desktop Questions & Answers

While Connecting to Google networking. Error = Unusual traffic from your computer network.

Hello, I am working in office, where, more than 60 clients machines (only 16 machines are on windows) are there and one server Centos Server, I have configured clients with server, so that internet will be used form only one IP. Only 1 ip is assigned, but now a days, my client machines are... (2 Replies)
Discussion started by: RedRocks!!
2 Replies

7. UNIX and Linux Applications

Calender/docket software

We are running in a Linux/Samba environment. Can anyone suggest calendar/docket software that will run in our environment? (0 Replies)
Discussion started by: kbweiss
0 Replies

8. UNIX for Dummies Questions & Answers

Awk/sed to play on calender

Hello Awk'inas/Sed'ers; This is keep ringing on my mind for a while, onto play in calender with awk or sed :cool:. Given a date, month and Year would like to find out the day corresponding to it. Am still a noob on awk and sed, hence would like to learn it from your responses. Here it is;... (11 Replies)
Discussion started by: sathyaonnuix
11 Replies

9. Shell Programming and Scripting

Enter number of days and get calender

Friends need assistance in getting a script either on shell or perl. Below is the situation Taking Today's calender into consideration with Month,Day,Year current .Using that i would like give number of days to get its month,day,year for future or past calender depending on the + or - days... (8 Replies)
Discussion started by: ajayram_arya
8 Replies

10. Shell Programming and Scripting

Facing problem while having time popup from inline calender

I have CGI Perl script that contains date column and date popup will be displayed from inline calender. I had a html script for the same and converted the same to CGI script. html page worked fine but no luck with CGI script. Could anyone please look into the below script and let me know... (1 Reply)
Discussion started by: scriptscript
1 Replies
CAL(1)							    BSD General Commands Manual 						    CAL(1)

NAME
cal, ncal -- displays a calendar and the date of easter SYNOPSIS
cal [-jy] [[month] year] cal [-j] -m month [year] ncal [-jJpwy] [-s country_code] [[month] year] ncal [-Jeo] [year] DESCRIPTION
The cal utility displays a simple calendar in traditional format and ncal offers an alternative layout, more options and the date of easter. The new format is a little cramped but it makes a year fit on a 25x80 terminal. If arguments are not specified, the current month is dis- played. The options are as follows: -J Display Julian Calendar, if combined with the -e option, display date of easter according to the Julian Calendar. -e Display date of easter (for western churches). -j Display Julian days (days one-based, numbered from January 1). -m month Display the specified month. -o Display date of orthodox easter (Greek and Russian Orthodox Churches). -p Print the country codes and switching days from Julian to Gregorian Calendar as they are assumed by ncal. The country code as deter- mined from the local environment is marked with an asterisk. -s country_code Assume the switch from Julian to Gregorian Calendar at the date associated with the country_code. If not specified, ncal tries to guess the switch date from the local environment or falls back to September 2, 1752. This was when Great Britain and her colonies switched to the Gregorian Calendar. -w Print the number of the week below each week column. -y Display a calendar for the specified year. A single parameter specifies the year (1 - 9999) to be displayed; note the year must be fully specified: ``cal 89'' will not display a calen- dar for 1989. Two parameters denote the month and year; the month is either a number between 1 and 12, or a full or abbreviated name as specified by the current locale. Month and year default to those of the current system clock and time zone (so ``cal -m 8'' will display a calendar for the month of August in the current year). A year starts on Jan 1. SEE ALSO
calendar(3), strftime(3) HISTORY
A cal command appeared in Version 5 AT&T UNIX. The ncal command appeared in FreeBSD 2.2.6. AUTHORS
The ncal command and manual were written by Wolfgang Helbig <helbig@FreeBSD.org>. BUGS
The assignment of Julian--Gregorian switching dates to country codes is historically naive for many countries. BSD
November 23, 2004 BSD
All times are GMT -4. The time now is 04:55 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy