Get the current date and time

Peace upon you every one,

i’m trying to get the current date and time using the stander C library or the Linux native API
i was trying to call the function gettimeofday() but i’m having a problem identifying the parameters type !!!

i’m trying to call the function like that

	//get current time
	struct timeval current_time = {0,0};

	int result = gettimeofday(&current_time,NULL);


but i get the following compiler error (i’m using gcc)

main_code.c: In function ‘main’:
main_code.c:35:9: error: variable ‘current_time’ has initializer but incomplete type
main_code.c:35:9: warning: excess elements in struct initializer
main_code.c:35:9: warning: (near initialization for ‘current_time’)
main_code.c:35:9: warning: excess elements in struct initializer
main_code.c:35:9: warning: (near initialization for ‘current_time’)
main_code.c:35:17: error: storage size of ‘current_time’ isn’t known

any way do you know a good method to use …??

Works for me. Looks like you didn’t

#include <sys/time.h>

as the man page for gettimeofday(3) says, to get the definition of struct timeval.

And next time please mention in the thread title that it is about C programming. It helps people to go for the threads about languages they know and thus for you to get a better and quicker answer (hm, in fact the answer could not be much quicker in this case :wink: )