package main
import (
"database/sql"
"fmt"
"log"
"time"
_ "github.com/go-sql-driver/mysql"
)
func main() {
// Replace "username", "password", "dbname" with your MySQL credentials and database name
db, err := sql.Open("mysql", "username:password@tcp(localhost:3306)/dbname")
if err != nil {
log.Fatal(err)
}
defer db.Close()
// Replace "your_table" with the actual table name
query := fmt.Sprintf("SELECT * FROM your_table WHERE created_at >= '%s'", getTimestamp())
rows, err := db.Query(query)
if err != nil {
log.Fatal(err)
}
defer rows.Close()
for rows.Next() {
// Handle each row data as needed
var id int
var name string
var createdAt time.Time
err := rows.Scan(&id, &name, &createdAt)
if err != nil {
log.Fatal(err)
}
// Process the row data
fmt.Printf("ID: %d, Name: %s, Created At: %s\n", id, name, createdAt)
}
}
func getTimestamp() string {
// Replace "your_timezone" with the desired timezone (e.g., "UTC", "America/New_York")
location, err := time.LoadLocation("your_timezone")
if err != nil {
log.Fatal(err)
}
// Replace "your_layout" with the desired timestamp layout (e.g., "2006-01-02 15:04:05")
layout := "your_layout"
// Get the current time in the specified timezone and format
currentTime := time.Now().In(location)
return currentTime.Format(layout)
}