The Web Design Group

... Making the Web accessible to all.

Welcome Guest ( Log In | Register )

> Date
tudsy
post Jun 26 2018, 11:07 AM
Post #1


Advanced Member
****

Group: Members
Posts: 179
Joined: 30-September 14
Member No.: 21,611



Hi

Just one question.


I am trying to put a date in a database. But I am not having much luck. I have created the date object. But what do I put in the insert query for the dt variable?


Thanks.


https://ecovib2d.com.au/ECOVIB2D/MYART/index.txt
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
 
Reply to this topicStart new topic
Replies
CharlesEF
post Jun 26 2018, 02:52 PM
Post #2


Programming Fanatic
********

Group: Members
Posts: 1,672
Joined: 27-April 13
From: Edinburg, Texas
Member No.: 19,088



Since it's been awhile since I've inserted any dates I went back and looked at some old code. I used the date and strtotime commands, like this:
CODE
$date = date(DATE_DB, strtotime($_POST['date']));
DATE_DB is the date format I want stored in the database. Of course, you want to validate any user data before you insert it.

To be honest, since the date command returns a string formatted as a date I wonder if that old code was really needed. Seems my original idea should work without any problems, $date = "2018/06/30";. Of course, you should validate the date before you try to store it, I don't think MySQL will store invalid dates.

This post has been edited by CharlesEF: Jun 26 2018, 03:21 PM
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post

Posts in this topic


Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 



- Lo-Fi Version Time is now: 20th October 2019 - 09:22 PM