I am using the vue-ctk-date-time-picker to display a date time picker modal where users can pick date and time. I use a minDate such that users cannot pick date and time less than the current date and time. This works perfectly with format YYYY-MM-DD HH:mm:ss, but I needed the AM and PM format so I changed the format to YYYY-MM-DD HH:mm a. Now, the PM equivalent of the AM date is also being disabled.
For example, its 8:30 AM, so the picker disables all minutes upto 30 and users can only select 31, 32 and so on. But if I select PM, the minutes are still disabled, ie, the users are only able to pick from 31, when its not even PM yet.
Has anyone faced this problem? Is there a problem with package itself?
For anyone else having this problem, this is the solution according to the document here: https://github.com/chronotruck/vue-ctk-date-time-picker#behaviour
In order to avoid having too much properties in the component, We're
adding a behaviour property that is an object including some annex
behaviour values.
The default value for this object is:
{
time: {
nearestIfDisabled: true;
}
}
To override those values, pass a new object with the values you want
to override:
<ctk-date-time-picker
:behaviour="{
time: {
nearestIfDisabled: false
}
}"
/>
Related
I have this element:
<v-text-field
label="Choose a time"
type="time"
mask="time"
step="1800"
prepend-inner-icon="access_time"
v-model="expiryTime"
:rules="[v => !!v || 'Time is required']"
required
#change="getTime"
></v-text-field>
I want to trigger the getTime method to convert the v-model value into a h:mm format. As I've been testing I have entered 12:00 pm each time as the value for expiryTime and have done the following:
getTime(){
alert(moment().format('h:mm')) //returns current time in x:xx format
alert(this.expiryTime); // Returns '1200'
alert(moment(this.expiryTime).format('h:mm')); // returns '4:26, expect 12:00
alert(moment(this.expiryTime, 'h:mm')); // returns 'Sat Aug 17 2019 12:00:00 GMT-0600', expect 12:00
Basically I'm getting some unexpected values and I don't know why. If I can get the current time in the top alert I am rather confused about how formatting the expiryTime data the same ways ends up being 4:26. And the final alert returns the entire time with the date and etc.
Can someone please explain how I can convert the expiryTime data to be in h:mm format properly?
The moment(String) constructor takes either a ISO 8601 string, or an RFC2822 date time string. If neither of those standards are used, the format must be specified as the second argument of the constructor.
expiryTime (1200) is in the form of hmm, but you had specified h:mm, which would've required a colon between the hour and minutes for moment to parse the date correctly. The fix is to remove the colon.
console.log(moment(1200, 'hmm').format('h:mm'))
console.log(moment(135, 'hmm').format('h:mm'))
console.log(moment(2001, 'hmm').format('h:mm'))
<script src="https://unpkg.com/moment#2.24.0/moment.js"></script>
If you run a line like this in a Playground in the US:
let today = Date()
You'll see output like this to the right of the source code:
"Sep 26, 2016, 8:17 PM"
That appears to be the date, displayed in the local time zone, using medium date and time style.
How does that work?
If you try to print the date:
print("today = \(today)"
You'll see "Today = 2016-09-27 00:18:55 +0000\n", which is UTC, and appears to be unix date format.
What function is the Playground using to display the date when you first create a date? Is there a way to get to that output format from code or from the debug console?
Up until now I've created a date formatter that I use to log dates, display them in the console, etc.
It's lurking in CustomPlaygroundQuickLookable protocol, which Date conforms to:
if case .text(let str) = today.customPlaygroundQuickLook {
print(str)
}
In my view model i have several DateTime fields. I've decorated them with DisplayFormat attribute to give them date time format:
public class MyModel{
[DisplayFormat(DataFormatString = "{0:dd.MM.yyyy}")]
public DateTime? ReceivedDate{get;set;}
//omitted for brevity
}
This is the View:
<div>#Html.DisplayFor(x=>x.ReceivedDate)</div>
Now when date is say 12 July 1985, it'll display 07.12.1985 (Day and month swapped). But if I set date to for example 13 July 1985 , it'll be just blank. So apparently MVC tries to match the entered date to some other format.
P.S. I first insert the model to database and then read the recently added model on another view.
I've found the problem that caused this issue. In my web.config file, there was the following entry:
<system.web>
<globalization enableClientBasedCulture="true" culture="auto:en-US" uiCulture="auto:en-US" />
</system.web>
So this was setting the current culture to US. After removing that entry the problem got solved. BTW, you can just set your desired culture instead of removing too.
I am working on script where users can make certain type of orders. Now when users make an order they can choose how long they wont it to last in # of days. Once the order is placed I need to approve their order and that approval date is recorded inside my database. Now what I need is to show inside their user panel how much days their package will last since the day of my approval. So for example if I approved their order September 08, 2013 and they choosed for the order to last 7 days, I wont them to see inside they panel for every next day they login how much days they have left, so 7days, 6days, 5days, etc... all the way to "0 Days" when they come to their panel on September 16, 2013.
I have following variables for those two values:
$row_ordersResults['date'] - the date I approved the order
$row_ordersResults['drip_feed'] - # of days they wont for their order to last
I did tried to lots of combinations by myself but I am totally stuck with this and cant make it work.
Thanks for help!
The libraries at momentjs.com is pretty cool. But if you just wanted something simple to calculate the "date difference" between two time values, there is a relatively simple way to do it. I assume you wanted it done in Javascript.
All you need to do is to clear out the hour/minute/second/millisecond fields of the two dates, calculate their differences in days. Put the script below in any web browser and you'll see how it works.
<script>
function foo() {
var d1 = new Date(2013, 8, 12, 13, 40, 1, 333); // any date value, last 4 params can be anything
var d2 = new Date(2013, 9, 3, 11, 42, 32, 533);
d1.setHours(0); d1.setMinutes(0); d1.setSeconds(0); d1.setMilliseconds(0);
d2.setHours(0); d2.setMinutes(0); d2.setSeconds(0); d2.setMilliseconds(0);
daysLeft = (d2.getTime() - d1.getTime())/(24*60*60*1000);
alert('Dear customer, there is(are) ' + daysLeft + ' day(s) left on your order!' );
}
</script>
Show Remaining Days on Order
EDIT: adding PHP version
<?php
$d1 = New DateTime('2013-08-28 06:25:00');
$d2 = new DateTime(); // now
$drip = 55;
$interval = $d2->diff($d1); // time difference
$days_left = $drip - $interval->format('%a'); // in days, subtract from drip
echo "There are $days_left days left\n";
?>
I hope I don't get marked down for not suggesting a specific answer, but time and date calculations are very tedious and JavaScript's Date() provides limited options. So rather than offer some ugly code, I suggest you take a look at moment.js at momentjs.com. Once you attach the script to your pages, you can easily manage all kind of date formats, and set up a function that will allow you to do math on dates and automatically generate your date ranges - it will even let you format them in to user friendly formats like "in 3 days", which I think is what you want. If your app has anything to do with time, and most do, I can't recommend Moment highly enough.
so my query has
where date_trunc('DAY', mh.end) > ?
However when I try to put stuff like "3/31/2012 12:00:00 AM" or "2012-01-31" in the cell, it complains about it not being Timestamp with TIMEZONE format. How can I get it to accept the date? I have been trying to search but I have not found other people having this problem (my search terms might have been off).
Ok I figured it out. I had to convert the date to Text using =TEXT(B1,"yyyy-mm-dd hh:mm:ss") After that it works fine