Sponsored Content
Top Forums Programming may be simple but i don't know -- Print current date from C program Post 15520 by Perderabo on Friday 15th of February 2002 08:21:10 AM
Old 02-15-2002
I just tried your code and I got:
2/15/102
which is the expected result since today is Feb 15, 2002.

Just as you are adding 1 to tm_mon, so must you add 1900 to tm_year.

If you are really getting 2/17/146, you must have a bug elsewhere.
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

How to subtract 2 hours from 'date' in shell ( /bin/sh ) script ?

I write a sh script that zip and copy to tape all files that older then 2 hours. 1. The way I choose is - touch a file with "now - 2 hours", then use fine with '! -newer' 2. Do you have any other idea to do it ? tnx. (1 Reply)
Discussion started by: yairon
1 Replies

2. UNIX for Dummies Questions & Answers

Don't Know to Rebuild Linux Kernel(URGENT)

Hello. I'm installing Oracle8i on Red Hat Linux Server 7.0. The Oracle documentation has some preinstallation request to be carried before installing the Oracle software. It asks to modify some SEMAPHORE & SHARED MEMORY values in to a specified file. And finally after updating this values it... (2 Replies)
Discussion started by: S.Vishwanath
2 Replies

3. UNIX for Dummies Questions & Answers

Don't hate me because I'm stupid...

Hi all, I don't know the first thing about Unix, but I would like to learn. I would like to know what the difference between Linux and Unix is, and where I can obtain a copy of either. Thanks :o (8 Replies)
Discussion started by: ThisIsNewToMe
8 Replies

4. Programming

a very simple question (but i don't know)

how to write a program that receive a string from keyboard and then print it out. i write a program: main() { char str; gets(str); printf(str); } but when i compile it, the system said something like "new line is not last charicter" and sometime the system said "a3.c is up to date"... (1 Reply)
Discussion started by: dell9
1 Replies

5. UNIX Desktop Questions & Answers

Genome Startmenu crashed why I don't Know ??

what I have to do ? (1 Reply)
Discussion started by: atiato
1 Replies

6. UNIX for Dummies Questions & Answers

I don't know where to start

I have been in computers for 30 years and know everything about MS, but nothing about anything else. Been developping websites (inter alia) running on MS servers using ASP's and vbScripts which apparently does not work under Unix. My own website is being hosted on a Unix server and I need to... (4 Replies)
Discussion started by: paul@cascom
4 Replies

7. UNIX for Dummies Questions & Answers

How a program to convert '|' delimited file into excel?

Hi All, I want to convert a '|' delimited file to excel file. I want it is an automated process (this means I need not to open excel, import and choose '|' delimited, then ... to generate an excel) I need to use a scripts or proram to convert the file. Do any one have this tools? A... (11 Replies)
Discussion started by: wilsonchan1000
11 Replies

8. UNIX for Dummies Questions & Answers

awk to print current date?

List, I want to print the first line of my text file (say "me you"), preceded by the current date/time. Something like (pseudo code): awk '{print date,$1}' I don't have a lot of awk knowledge (understatement), so forgive me if the answer is obvious... (3 Replies)
Discussion started by: philipz
3 Replies

9. UNIX for Dummies Questions & Answers

print all dates 100 days from current date

can anyone please suggest me on ideas to write a script which has to go back to 100 days from 'current date' and print the date of each day starting from 100th day to current day. (korn shell please) Thanks Pavan (5 Replies)
Discussion started by: pavan_test
5 Replies

10. UNIX for Dummies Questions & Answers

print previous month (current month minus 1) with Solaris date and ksh

Hi folks month=`date +%m`gives current month Howto print previous month (current month minus 1) with Solaris date and ksh (7 Replies)
Discussion started by: slashdotweenie
7 Replies
STRPTIME(3)								 1							       STRPTIME(3)

strptime - Parse a time/date generated withstrftime(3)

SYNOPSIS
array strptime (string $date, string $format) DESCRIPTION
strptime(3) returns an array with the $date parsed, or FALSE on error. Month and weekday names and other language dependent strings respect the current locale set with setlocale(3) ( LC_TIME). PARAMETERS
o $date ( string) - The string to parse (e.g. returned from strftime(3)). o $format ( string) - The format used in $date (e.g. the same as used in strftime(3)). Note that some of the format options available to strf- time(3) may not have any effect within strptime(3); the exact subset that are supported will vary based on the operating system and C library in use. For more information about the format options, read the strftime(3) page. RETURN VALUES
Returns an array or FALSE on failure. The following parameters are returned in the array +-----------+---------------------------------------------------+ |parameters | | | | | | | Description | | | | +-----------+---------------------------------------------------+ | | | | "tm_sec" | | | | | | | Seconds after the minute (0-61) | | | | | | | | "tm_min" | | | | | | | Minutes after the hour (0-59) | | | | | | | |"tm_hour" | | | | | | | Hour since midnight (0-23) | | | | | | | |"tm_mday" | | | | | | | Day of the month (1-31) | | | | | | | | "tm_mon" | | | | | | | Months since January (0-11) | | | | | | | |"tm_year" | | | | | | | Years since 1900 | | | | | | | |"tm_wday" | | | | | | | Days since Sunday (0-6) | | | | | | | |"tm_yday" | | | | | | | Days since January 1 (0-365) | | | | | | | |"unparsed" | | | | | | | the $date part which was not recognized using the | | | specified $format | | | | +-----------+---------------------------------------------------+ EXAMPLES
Example #1 strptime(3) example <?php $format = '%d/%m/%Y %H:%M:%S'; $strf = strftime($format); echo "$strf "; print_r(strptime($strf, $format)); ?> The above example will output something similar to: 03/10/2004 15:54:19 Array ( [tm_sec] => 19 [tm_min] => 54 [tm_hour] => 15 [tm_mday] => 3 [tm_mon] => 9 [tm_year] => 104 [tm_wday] => 0 [tm_yday] => 276 [unparsed] => ) NOTES
Note This function is not implemented on Windows platforms. Note Internally, this function calls the strptime() function provided by the system's C library. This function can exhibit noticeably different behaviour across different operating systems. The use of date_parse_from_format(3), which does not suffer from these issues, is recommended on PHP 5.3.0 and later. Note "tm_sec" includes any leap seconds (currently upto 2 a year). For more information on leap seconds, see the Wikipedia article on leap seconds. Note Prior to PHP 5.2.0, this function could return undefined behaviour. Notably, the "tm_sec", "tm_min" and "tm_hour" entries would return undefined values. SEE ALSO
checkdate(3), strftime(3), date_parse_from_format(3), DateTime.createFromFormat(3). PHP Documentation Group STRPTIME(3)
All times are GMT -4. The time now is 06:31 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy