# \[BASIC] 009 TIME GET DATE (วัน)

สวัสดีครับ สำหรับหัวข้อบทเรียนพื้นฐานบนบอร์ด HONEYLemon ที่ใช้งานผ่าน arduino library โดยเป็นการใช้งานเกี่ยวกับการอ่านข้อมูล Date ซึ่งจะทำการดึงข้อมูลจากอินเตอร์เน็ตผ่าน WiFi

อ่านข้อมูลเพิ่มเติมสำหรับการเชื่อมต่อ WiFi

{% content-ref url="/pages/-MA5r7zqnmaErAORBQ3y" %}
[\[BASIC\] 007 WiFi SETUP WiFi (ต่อเน็ต)](/blogs/basic/basic-007-wifi-setup-wifi.md)
{% endcontent-ref %}

เมื่อเชื่อมต่อ WiFi ได้แล้วจากบทความข้างต้น ระบบก็จะทำการ sync เวลาให้อัตโนมัติ คราวนี้ก็ทำการดึงข้อมูลมาได้เลย

คำสั่งที่เกี่ยวข้อง

```
        getDate()       // อ่านค่าวันที่ ปี-เดือน-วัน (Year-Month-Day) (String)
        getDate_Day()   // อ่านค่าวันที่ Day 1-31    (int)
        getDate_Mouth() // อ่านค่าเดือน Mouth 1-12 (int)
        getDate_Year()  // อ่านค่าปี (ค.ศ.)        (int)
```

ตัวอย่างการใช้งาน

```
    String date = lemon.getDate();       // อ่านค่าวันที่ ปี-เดือน-วัน (Year-Month-Day) (String)
    int d = lemon.getDate_Day();   // อ่านค่าวันที่ Day 1-31    (int)
    int m = lemon.getDate_Mouth(); // อ่านค่าเดือน Mouth 1-12 (int)
    int y = lemon.getDate_Year();  // อ่านค่าปี (ค.ศ.)        (int)
```

**ตัวอย่าง source code**

```
/*
    Basic : การเขียนโปรแกรมกับอ่านค่าวันเวลาจากอินเตอร์เน็ตบนบอร์ดไมโครคอนโทรลเลอร์ HONEYLemon
*/
#include <HONEYLemon.h>

#define WIFI_SSID  "WiFi_Name"      // ตั้งค่าชื่อ WiFi
#define WIFI_PASS  "WiFi_Password"  // ตั้งค่ารหัสผ่าน WiFi

void setup()
{
    lemon.begin();          // เรียกใช้งานฟังก์ชั่นเริ่มต้นของบอร์ด HONEYLemon

    Serial.begin(115200);   // เรียกใช้งาน Serial
    lemon.debug(Serial);    // ขอดู debug ของบอร์ด HONEYLemon ผ่าน Serial

    // เรียกการใช้งานการตั้งค่า WiFi
    lemon.setupWiFi(WIFI_SSID, WIFI_PASS);
}

void loop()
{
    /*
        getDate()       // อ่านค่าวันที่ ปี-เดือน-วัน (Year-Month-Day) (String)
        getDate_Day()   // อ่านค่าวันที่ Day 1-31    (int)
        getDate_Mouth() // อ่านค่าเดือน Mouth 1-12 (int)
        getDate_Year()  // อ่านค่าปี (ค.ศ.)        (int)
    */

    // กำหนดตัวแปรสำหรับเก็บข้อมูลชื่อวัน
    String textDays[] ={"Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"};
    Serial.print( textDays[lemon.getDate_DayOfWeek()] );  // แสดงผลชื่อวัน

    Serial.println( lemon.getDate() );  // แสดงผล ปี-เดือน-วัน Year-Month-Day

    //Serial.println( lemon.getDate_Day() );    // แสดงผลวันที่
    //Serial.println( lemon.getDate_Month() );  // แสดงผลเดือนที่
    //Serial.println( lemon.getDate_Year() );   // แสดงผลปีที่ (ค.ศ.)

    delay(1000);    // รอ 1000 มิลลิวินาที (1 วินาที)
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://lemon.honey.co.th/blogs/basic/basic-009-time-get-date.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
