这两个datetime
string
是平等的。我们如何将这两个字符串datetime
与laravel
进行比较。
$str_date1='08/09/2017';
$str_date2='8/9/2017';
如何将忽略datetime
这两个字符串0
与laravel进行比较。
答案 0 :(得分:3)
为了达到你所要求的,你需要Carbon
课程,你可以尝试这样的事情:
$date1 = Carbon\Carbon::parse($str_date1)->toDateTimeString();
$date2 = Carbon\Carbon::parse($str_date2)->toDateTimeString();
if($date1 == $date2)
{
// Do your code
}
希望这有帮助
答案 1 :(得分:2)
你应该试试这个:
import { Component, AfterViewInit, AfterContentInit } from '@angular/core';
import { AuthService } from '../../services/auth.service';
import { Router } from "@angular/router";
import * as d3 from "d3-selection";
@Component({
selector: 'app-dashboard',
templateUrl: './dashboard.component.html',
styleUrls: ['./dashboard.component.css']
})
export class DashboardComponent implements AfterViewInit, AfterContentInit {
user: Object;
teams: any;
constructor(
private authService: AuthService,
private router: Router
) { }
ngAfterContentInit() {
this.authService.getProfile().subscribe(profile => {
this.user = profile.user;
},
err => {
console.log(err);
return false;
});
this.authService.getAllTeams().subscribe(teams => {
// console.log(teams);
this.teams = Object.keys(teams).map(key => teams[key]);
// console.log(this.teams);
},
err => {
console.log(err);
return false;
});
}
ngAfterViewInit() {
this.authService.getAllTeams().subscribe(teams => {
// console.log(this.teams);
var team = [];
team = this.teams[0];
for (var i = 0; i < team.length; i++) {
var dataset = [];
dataset = [team[i].spAchieved, team[i].spEstimated];
// console.log(dataset);
var w = 100;
var h = 100;
var barPadding = 1;
var svg = d3.select("#chart .list-element:nth-child(" + (i + 1) + ") .graph")
.append("svg")
.attr("width", w)
.attr("height", h);
svg.selectAll("rect")
.data(dataset)
.enter()
.append("rect")
.attr("x", (d, i) => i * (w / dataset.length))
.attr("y", d => h - d)
.attr("width", w / dataset.length - barPadding)
.attr("height", d => d)
.attr("fill", (d) => "rgb(100, 0, " + (d * 5) + ")");
svg.selectAll("text")
.data(dataset)
.enter()
.append("text")
.text(d => d)
.attr("x", (d, i) => i * (w / dataset.length) + 15)
.attr("y", d => h - d);
};
},
err => {
console.log(err);
return false;
});
}
更新回答:
$str_date1='08/09/2017';
$str_date2='8/9/2017';
$date1 = strtotime($str_date1);
$date2 = strtotime($str_date2);
if($date1 == $date2){
//Your code
}
答案 2 :(得分:1)
将它们转换为DateTime然后进行比较。不需要使用像Carbon或任何花哨类或帮助者那样的东西。
$str_date1 = '08/09/2017';
$str_date2 = '8/9/2017';
$date1 = \DateTime::createFromFormat('d/m/Y', $str_date1);
$date2 = \DateTime::createFromFormat('d/m/Y', $str_date2);
if ($date1 > $date) {
// Your stuff
}
答案 3 :(得分:1)
# Let's first create a list of unsorted data.
# In this case, (A, C, B) are not in lexicographic order.
unsorted_data = [
'Report1.0REV_A.xlsx',
'Report1.0REV_C.xlsx',
'Report1.0REV_B.xlsx',
]
# The function "pick_letter" will be used later on. It is a very simple
# function comprised of only one statement. That is a very good candidate for a
# "lambda expression". But as you say that you are new to Python, I'll give two
# examples below. One using "lambda", the other using the function
# "pick_letter".
def pick_letter(value):
'''
This function takes a value and returns the 6th item from the end. The
value passed can be anythin that can be indexed, like strings or lists.
'''
return value[-6]
# Sorting the input data using "pick_letter"
#
# "sorted" takes an optional argument "key" which holds a function. This
# function will be called for each element in the list and must return
# "something". The list will returned by this "something". In your case, you
# want the 6th element from the end, so we use "pick_letter".
sorted_data_1 = sorted(unsorted_data, key=pick_letter)
# As mentioned above, the same can be achieved by a "lambda" expression. This
# saves us the definition of the "pick_letter" function. Using "lambdas" is
# debatable. They have no name, no doc-string and may be harder to understand.
# But this case is *so* simple that it really is a prime candidate for a
# lambda:
sorted_data_2 = sorted(unsorted_data, key=lambda x: x[-6])
print('Unsorted data:', unsorted_data)
print('Sorted data (using pick_letter):', sorted_data_1)
print('Sorted data (using lambda):', sorted_data_2)
# Now that it is sorted, you can pick the last element using [-1]:
print('Last element:', sorted_data_1[-1])
# Apart from sorting, we can create a new list containing only the 6th
# character from the end for each element. The code below is a so called
# "list comprehension". It is a Python feature which allows you to quickly
# create lists (and other similar collections) from other iterables. In
# this case, the list will have the same ordering as the input
# (unsorted_data)
characters = [filename[-6] for filename in unsorted_data]
print('Characters:', characters)
根据您的需要,PHP附带了区分日期的功能。 http://php.net/manual/en/class.datetime.php