Real time without Realtime clock?

Hello I'm working on a temperature logging to mysql. everything is working great and i'll post the arduino code below but my problem is. I would like to add Time and date to my project without a Real time clock module or chip. Everything so far i found online is for different RTC modules and chips and i do not know i be able to get the time and date without it. i don't have a real time clock module or chip. Can someone please help me out. This is my code below.

#include <DHT.h>
#include <Ethernet.h>
#include <SPI.h>

byte mac[] = { 0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x01 }; // RESERVED MAC ADDRESS
EthernetClient client;

#define DHTPIN 6 // SENSOR PIN
#define DHTTYPE DHT22 // SENSOR TYPE - THE ADAFRUIT LIBRARY OFFERS SUPPORT FOR MORE MODELS
DHT dht(DHTPIN, DHTTYPE);

long previousMillis = 0;
unsigned long currentMillis = 0;
long interval = 1000; // READING INTERVAL

int t = 0;	// TEMPERATURE VAR
int h = 0;	// HUMIDITY VAR
String data;

void setup() { 
	Serial.begin(115200);

 pinMode(7, OUTPUT);      // sets the digital pin as output
 pinMode(5, OUTPUT);      // sets the digital pin as output
 digitalWrite(7, HIGH);   // sets +5v for the sensor
 digitalWrite(5, LOW);    // sets gnd for the sensor

	if (Ethernet.begin(mac) == 0) {
		Serial.println("Failed to configure Ethernet using DHCP"); 
	}

	dht.begin(); 
	delay(10000); // GIVE THE SENSOR SOME TIME TO START

	h = (int) dht.readHumidity(); 
	t = (int) dht.readTemperature(); 

	data = "";
}

void loop(){
  

	currentMillis = millis();
	if(currentMillis - previousMillis > interval) { // READ ONLY ONCE PER INTERVAL
		previousMillis = currentMillis;
		h = (int) dht.readHumidity();
		t = (int) dht.readTemperature();
	}

data = "temp1=";

data.concat(t);

data.concat("&hum1=");

data.concat(h);


	if (client.connect("yoursite.com",80)) { // REPLACE WITH YOUR SERVER ADDRESS
		client.println("POST /add.php HTTP/1.1"); // path to the add.php file
		client.println("Host: yoursite.com"); // SERVER ADDRESS HERE TOO
		client.println("Content-Type: application/x-www-form-urlencoded"); 
		client.print("Content-Length: "); 
		client.println(data.length()); 
		client.println(); 
		client.print(data); 
     
        Serial.print(data); 
           Serial.print("\n"); 
	} 

	if (client.connected()) { 
		client.stop();	// DISCONNECT FROM THE SERVER
	}

	delay(7000); // WAIT FIVE MINUTES BEFORE SENDING AGAIN
}

You can modify add.php to add the pc time before inserting the record into the database. Not quite real time but might be good enough.

If it's not good enough, get a RTC.

Hello Sterretje thank you. But there is already a timestamp in the mysql showing what is suppose to be current time and date problem is it's 2 hours behind me. I'm EST time and that time shows up as MT time. Which i think that is where the server is located at. I don't know how to change it to show my current time and not what the server time is.

Did you write add.php? Or was it provided?

I'm no longer familiar with php. I'm reasonably sure that you can get the utc time and add your own offset/timezone.

I have found something to use a ntp time i did find a Sketch and a library they have Examples for arduino and ESP. Different time zones as well. All i had to do is find a time zone ntp address. Here is the Sketches and library to the NTP and Here is the address to where i found my time at. But it might be different for other people might have to search online. I hope this will help others.

Hello i did mange to find a RTC module. i have a DS3231 But i would still like to use the NTP server to update the clock. I searched online and i came across a site for the clock module and this is the sketch they had

/*
 * NAME: NTP2RTC
 * DATE: 2012-02-19
 *  URL: http://playground.arduino.cc/Main/DS1307OfTheLogshieldByMeansOfNTP
 *
 * PURPOSE:
 * Get the time from a Network Time Protocol (NTP) time server
 * and store it to the RTC of the adafruit logshield
 *
 * NTP is described in:
 * http://www.ietf.org/rfc/rfc958.txt (obsolete)
 * http://www.ietf.org/rfc/rfc5905.txt 
 *
 * based upon Udp NTP Client, by Michael Margolis, mod by Tom Igoe
 * uses the RTClib from adafruit (based upon Jeelabs)
 * Thanx!
 * mod by Rob Tillaart, 10-10-2010
 * 
 * This code is in the public domain.
 * 
 */



/*
 Dit is door BlackDog aangepastde code, er is gespeeld met de "delay" tijden!
 Zet de goede NTP server aan!
 DE serial poort snelheid staat op 115200
 
 
 sketch uses the code from TimeNTP example to acquire a unix time stamp.
 sets an RTC with that time stamp, and uses the RTC as synch provider for the Time library
 */

#include <Time.h> 
#include <Ethernet.h>
#include <EthernetUdp.h>
#include <SPI.h>
#include<Wire.h>;
//#include <DS1307RTC.h>
#include <DS3232RTC.h> //alternative drop in replacement //http://github.com/JChristensen/DS3232RTC 
//the ds3232 library will help with alarm setting and temperature reading with ds3231rtc

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //controleer het MAC adres van je Ethernet Shield

// NTP Servers:
IPAddress timeServer(192, 168, 0, 1); // Blackdog Time Server
// IPAddress timeServer(192.79.237.14); // ntp1.nl.net, de tijdserver voor Nederland
// IPAddress timeServer(132, 163, 4, 102); // time-b.timefreq.bldrdoc.gov
// IPAddress timeServer(132, 163, 4, 103); // time-c.timefreq.bldrdoc.gov

const int timeZone = 2;     // Central European Time
//const int timeZone = -5;  // Eastern Standard Time (USA)
//const int timeZone = -4;  // Eastern Daylight Time (USA)
//const int timeZone = -8;  // Pacific Standard Time (USA)
//const int timeZone = -7;  // Pacific Daylight Time (USA)

EthernetUDP Udp;
unsigned int localPort = 8888;  // local port to listen for UDP packets

void setup() 
{
  Serial.begin(115200);    // let op deze poort snelheid, dit is geen 9600!!!
  delay(1000);
  Serial.println("TimeNTP Example");
  if (Ethernet.begin(mac) == 0) {
    // no point in carrying on, so do nothing forevermore:
    while (1) {
      Serial.println("Failed to configure Ethernet using DHCP");
      delay(100);
    }
  }
  Serial.print("IP number assigned by DHCP is ");
  Serial.println(Ethernet.localIP());
  Udp.begin(localPort);
  Serial.println("waiting for sync");
  RTC.set(getNtpTime());
  setSyncProvider(RTC.get);
  if(timeStatus()!= timeSet) 
    Serial.println("Unable to sync with the RTC");
  else
    Serial.println("RTC has set the system time");    
}

void loop()
{  
  if (timeStatus() == timeSet) {
    digitalClockDisplay();
  } 
  else {
    Serial.println("The time has not been set. Please run the Time");
    Serial.println("TimeRTCSet example, or DS1307RTC SetTime example.");
    Serial.println();
    delay(100);
  }
  delay(100);

}

void digitalClockDisplay(){
  tmElements_t tm;
  Serial.print(hour());
  printDigits(minute());
  printDigits(second());
  Serial.print(" ");
  Serial.println();
//  Serial.print(day());
//  Serial.print(" ");
//  Serial.print(month());
//  Serial.print(" ");
//  Serial.print(year()); 
//  Serial.println(); 
//  Serial.print("Unix Time:  ");
//  Serial.println(makeTime(tm));
}

void printDigits(int digits){
  // utility for digital clock display: prints preceding colon and leading 0
  Serial.print(":");
  if(digits < 10)
    Serial.print('0');
  Serial.print(digits);
}

/*-------- NTP code ----------*/

const int NTP_PACKET_SIZE = 48; // NTP time is in the first 48 bytes of message
byte packetBuffer[NTP_PACKET_SIZE]; //buffer to hold incoming & outgoing packets

time_t getNtpTime()
{
  while (Udp.parsePacket() > 0) ; // discard any previously received packets
  Serial.println("Transmit NTP Request");
  sendNTPpacket(timeServer);
  uint32_t beginWait = millis();
  while (millis() - beginWait < 1500) {
    int size = Udp.parsePacket();
    if (size >= NTP_PACKET_SIZE) {
      Serial.println("Receive NTP Response");
      Udp.read(packetBuffer, NTP_PACKET_SIZE);  // read packet into the buffer
      unsigned long secsSince1900;
      // convert four bytes starting at location 40 to a long integer
      secsSince1900 =  (unsigned long)packetBuffer[40] << 24;
      secsSince1900 |= (unsigned long)packetBuffer[41] << 16;
      secsSince1900 |= (unsigned long)packetBuffer[42] << 8;
      secsSince1900 |= (unsigned long)packetBuffer[43];
      return secsSince1900 - 2208988800UL + timeZone * SECS_PER_HOUR;
    }
  }
  Serial.println("No NTP Response :-(");
  return 0; // return 0 if unable to get the time
}

// send an NTP request to the time server at the given address
void sendNTPpacket(IPAddress &address)
{
  // set all bytes in the buffer to 0
  memset(packetBuffer, 0, NTP_PACKET_SIZE);
  // Initialize values needed to form NTP request
  // (see URL above for details on the packets)
  packetBuffer[0] = 0b11100011;   // LI, Version, Mode
  packetBuffer[1] = 0;     // Stratum, or type of clock
  packetBuffer[2] = 6;     // Polling Interval
  packetBuffer[3] = 0xEC;  // Peer Clock Precision
  // 8 bytes of zero for Root Delay & Root Dispersion
  packetBuffer[12]  = 49;
  packetBuffer[13]  = 0x4E;
  packetBuffer[14]  = 49;
  packetBuffer[15]  = 52;
  // all NTP fields have been given values, now
  // you can send a packet requesting a timestamp:                 
  Udp.beginPacket(address, 123); //NTP requests are to port 123
  Udp.write(packetBuffer, NTP_PACKET_SIZE);
  Udp.endPacket();
}

I get a error from it i don't understand. If i select the uno board in the board menu i get no errors but sense i current do not have a uno board I'm using a m0 pro board i get this error message.

Arduino: 1.8.5 (Windows 10), Board: "Arduino M0 Pro (Programming Port)"

Build options changed, rebuilding all
In file included from C:\Users\Programmin-Computer\AppData\Local\Arduino15\packages\arduino\tools\CMSIS-Atmel\1.1.0/CMSIS/Device/ATMEL/samd21/include/samd21.h:69:0,

                 from C:\Users\Programmin-Computer\AppData\Local\Arduino15\packages\arduino\tools\CMSIS-Atmel\1.1.0/CMSIS/Device/ATMEL/samd.h:105,

                 from C:\Users\Programmin-Computer\AppData\Local\Arduino15\packages\arduino\tools\CMSIS-Atmel\1.1.0/CMSIS/Device/ATMEL/sam.h:470,

                 from C:\Users\Programmin-Computer\AppData\Local\Arduino15\packages\arduino\hardware\samd\1.6.19\cores\arduino/Arduino.h:48,

                 from sketch\sketch_dec05a.ino.cpp:1:

C:\Users\Programmin-Computer\AppData\Local\Arduino15\packages\arduino\tools\CMSIS-Atmel\1.1.0/CMSIS/Device/ATMEL/samd21/include/samd21g18a.h:487:38: error: expected ')' before '*' token

 #define RTC               ((Rtc      *)0x40001400UL) /**< \brief (RTC) APB Base Address */

                                      ^

C:\Users\Programmin-Computer\Documents\Arduino\libraries\DS3232RTC/DS3232RTC.h:116:18: note: in expansion of macro 'RTC'

 extern DS3232RTC RTC;

                  ^

C:\Users\Programmin-Computer\AppData\Local\Arduino15\packages\arduino\tools\CMSIS-Atmel\1.1.0/CMSIS/Device/ATMEL/samd21/include/samd21g18a.h:487:38: error: expected ')' before '*' token

 #define RTC               ((Rtc      *)0x40001400UL) /**< \brief (RTC) APB Base Address */

                                      ^

C:\Users\Programmin-Computer\Documents\Arduino\libraries\DS3232RTC/DS3232RTC.h:116:18: note: in expansion of macro 'RTC'

 extern DS3232RTC RTC;

                  ^

C:\Users\PROGRA~1\AppData\Local\Temp\arduino_modified_sketch_18948\sketch_dec05a.ino: In function 'void setup()':

sketch_dec05a:77: error: request for member 'set' in '1073746944u', which is of pointer type 'Rtc*' (maybe you meant to use '->' ?)

   RTC.set(getNtpTime());

       ^

sketch_dec05a:78: error: request for member 'get' in '1073746944u', which is of pointer type 'Rtc*' (maybe you meant to use '->' ?)

   setSyncProvider(RTC.get);

                       ^

exit status 1
request for member 'set' in '1073746944u', which is of pointer type 'Rtc*' (maybe you meant to use '->' ?)

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

I'm not sure what to do can someone please help me out?