storing date into a file from a program


 
Thread Tools Search this Thread
Top Forums Programming storing date into a file from a program
# 1  
Old 01-17-2006
storing date into a file from a program

hi all:

i want to store the current date in to a file from a program.
every time i execute the prg the date should get appended into the file.
help me plz
# 2  
Old 01-17-2006
hope this helps,
modify format specifier according to your need.

Code:
#include <time.h>
#include <stdio.h>
int main()
{
FILE *fp;
time_t  currtime;
 struct tm *curr = NULL;
fp=fopen("logfile", "a+");
if( fp == NULL )
{
fprintf(stderr, "file open error\n");
exit(1);
}
 time(&currtime);
 curr=localtime(&currtime);
fprintf(fp, "Year: %04d Month: %02d Day: %02d Hour: %02d Minute: %02d Second: %02d\n", 1900 + curr->tm_year,curr->tm_mon
 + 1, curr->tm_mday, curr->tm_hour, curr->tm_min, curr->tm_sec);
}

# 3  
Old 01-17-2006
thanks matrixmadan

thank u .
the code really worked.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Finding specific string in file and storing in another file

Text in input file is like this <title> <band height="21" isSplitAllowed="true" > <staticText> <reportElement x="1" y="1" width="313" height="20" key="staticText-1"/> <box></box> <textElement> <font fontName="Arial" pdfFontName="Helvetica-Bold"... (4 Replies)
Discussion started by: aankita30
4 Replies

2. Programming

Storing a Temporary File Using C

How would someone save a file such as /etc/vpnc/test.conf locally into a temp file, so it can be queried? So for example if I used rsync to copy this file locally, how would I add that to a temp_file variable and discard it using unlink? #include <stdio.h> #include "error.h" ... (15 Replies)
Discussion started by: metallica1973
15 Replies

3. Shell Programming and Scripting

perl : searching for month and storing the date and time in an array

I am writing the code in perl. I have an array in perl and each variable in the array contains the data in the below format Now I need to check the below variable w.r.t system month I need to store the date and time(Tue Aug 7 03:54:12 2012) from the below data into file if contains only 'Aug'... (5 Replies)
Discussion started by: giridhar276
5 Replies

4. UNIX for Dummies Questions & Answers

Storing PDF File

Hi, We have generated Some BO reports and These BO reports Needs to be stored in PDF File format in unix server. Will Unix Support to store PDF Files ? Many Thanks Sashu (1 Reply)
Discussion started by: Sashanth_S
1 Replies

5. Programming

Storing the output of a Unix cmd in my C program

Hello experts, How can I retrieve the output from a Unix command and use it as string variable in my C program? For example, when I issue the command 'date' I get: Tue Jun 11 09:54:16 EEST 2009 I do not want to redirect the output of the command to a file and then open the file from... (3 Replies)
Discussion started by: Goseib
3 Replies

6. Shell Programming and Scripting

date capturing regex and storing

Hi all I need help on how to store two or more date formates captured using regex from an input sentence in PERL ? For example, I have an input sentence consisting of two dates such as : The departure date is August 12, 2009 and arrival date is 20.08.2009. Now, I want to capture the two... (4 Replies)
Discussion started by: my_Perl
4 Replies

7. UNIX for Dummies Questions & Answers

Retreiving and storing date...

First of all want to apologize for such a simple question. Very "new" to UNIX and have just taken a small intro class. I need to pull back YYYYMMDD and store it in a field to be used later. I figured out date "+%Y%m%d" returns the date in that format, just not sure how to store it. I am... (7 Replies)
Discussion started by: cards0622
7 Replies

8. Shell Programming and Scripting

Help in a Recursive date program!!!!

Hi, I need a recursive program which when run appends todays date,month and year automatically to the existing file names.. I have aaa.txt file with some 90 odd file names. aa.bb_cc aa.bb_cc . . . aa.yy.zz When the script is run for today,it should give me like.. ... (22 Replies)
Discussion started by: kumarsaravana_s
22 Replies

9. Programming

date calculation program

Hi One of my vendor based tool is giving date in no. of days since 1900-01-01. So, I want to display in CCYYMMDD format. For ex:- Vendor based tool is giving as 38790 days since 1900-01-01 corresponding to12/sep/2006 Does anybody has the... (1 Reply)
Discussion started by: axes
1 Replies

10. UNIX for Advanced & Expert Users

date program in ksh

#Author : kkodava #!/usr/bin/ksh #Use of this program is You can findout the no of days & day of starting and ending dates #usage no_of_days startdate<yyyymmdd> enddate<yyyymmdd> syy=`echo $1|cut -c1-4` smm=`echo $1|cut -c5-6` sdd=`echo $1|cut -c7-8` eyy=`echo $2|cut -c1-4` emm=`echo... (1 Reply)
Discussion started by: krishna
1 Replies
Login or Register to Ask a Question