php


Checking if the date/time is less than a date provided?


I'm implementing the following in PHP with stores this string in the DB for the "created_at" column: Wed, 17 Dec 2014 14:53:02 +1100.
$created_at = date('r', $insta['created_time']);
Now I'd only like to do the insert if $created_at is more than a certain date, for example:
if ($created_at > "Wed, 15 Dec 2014 00:00:00 +1100") { //insert in to db }
That doesn't work though. I'd usually use strtotime() but unsure how to go about it when the data is set in that format. Also, the column type is varchar(255).
Aside from your question, you need to store datetime data in a datetime column. Mysql has specific functions and formatting for this reason. But, in order to store it will need to be in Y-m-d H:i:s format. Doing this will save you big hassles down the road.
In regards to your question, you can use PHP's DateTime class if you are using PHP version 5.2+.
$compareTime = new DateTime('2014-12-15 00:00:00'); //new datetime object//
$createdTime = new DateTime($created_at); //converts db into datetime object//
if ($createdTime > $comparedTime) { ..insert into DB.. }; //compare them//
Why are you storing WED in database..just store date with the php function date("Y-m-d H:i:s") and the table field type will be date..
This way mysql automatically give u facility to compare two dates. You can simply use if else statement to compare two dates.
for PHP version >= 5.3
Use date_create_from_format or DateTime::createFromFormat
Although I think strtotime would also work but to be sure pass date time format and value to above function. For detail of format see documentation.
Use strtotime().
$created_at = strtotime($insta['created_time']);
$checkdate = strtotime(date('Y-m-d H:i:s')); //here we have to insert check date
if($created_at > $checkdate){
}

Related Links

Select time from base as UNIX_TIMESTAMP(time) laravel 5
Easiest way to convert existing table to Laravel table schema
Show recently updated files on frontend using WP Filebase
Update table according to the selection box value in php
Dependency Injection or instantiating database class object
Find Duplicate in Text file
MySQL Error Code: 1064. You have an error in your SQL syntax (duplicate) [duplicate]
PHP - Using asterisk symbol in file path
For every other output in php
Disabling payment module in Hookpayment function PRESTASHOP
helper functions not loading laravel 5 - Call to undefined function
Output of exec() in php is empty array
What is the best way to reference and call info in a naming db
Laravel Authentication Using Parse.com PHP SDK
WooCommerce checkout field integer/numerical
Getting messages/mails sorted by date and time in Gmail API

Categories

HOME
qt
orientdb
webview
events
mc
cucumber
paypal-ipn
exchange-server
transactions
antd
vsts-build
google-play-services
gallery
jint
sentry
tfs2010
scrape
cuba-platform
jpa-2.0
mahout-recommender
corona
google-cloud-logging
c#-7.0
libgit2
batch-rename
quantitative-finance
channel
websphere-portal
managed-c++
code-climate
bitbake
fatfs
credit-card
es6-modules
dotcms
source-insight
infopath2010
netbios
sca
gnu-classpath
adminer
java-stream
db2-luw
xerces-c
orchardcms-1.8
textmate2
runtimeexception
unification
assert
plane
icepdf
raytracing
contactless-smartcard
notesview
type-inference
nuclio
ipp-protocol
renderman
embedded-v8
android-sharing
line-intersection
gnome-terminal
ptvs
stateless-session-bean
lvalue
rustdoc
wildfly-9
ndk-build
django-testing
raw-sockets
frame-grab
xcopy
i2b2
outlook.com
textpattern
cryptojs
bayesglm
stack-smash
blank-line
wlanapi
fantom
android-handler
alwayson
com0com
flow-js
ssmtp
rubber
rebar
ildasm
global-scope
smacss
producer
visual-studio-6
rpg
csslint
.htpasswd
refit
pageviews
flipboard
sensormanager
strcmp
saga
jquery-transit
ax
void-pointers
oscilloscope
ofstream
user-forums
ip-geolocation
playorm
android-dialog
msinfo32
memory-pool
qtextbrowser
representation
firefly-mv
upshot
digiflow
anonymous-types
iphone-sdk-4.3
processors
fuzzy-comparison
account-management

Resources

Encrypt Message



code
soft
python
ios
c
html
jquery
cloud
mobile