Hi Guys,
How on earth do we remove all off the rubbish from the Date & Time Created stamp?
Currently it shows like this:
Mon Jan 01 2018 00:00:00 GMT+0000 (GMT)
Basically i want it to look like this:
1 January 2018 | 9:40
Important forum update
This forum is migrating to one unified Wix community forum starting July 26th, and will be read-only during the process.
Wishlist Page is the official platform for requesting new features. You can vote, comment, and track the status of the requested features.
Can anyone assist me? For some reason when I placed the code in, I get an error in the closing marks.
Please let me know what line 26 should be changed to. Thanks!
just wanted to say thanks to Edgar and everyone for this thread. This issue was driving me crazy.
Ok, solved... my problem :)
Hi, I use code from Edgar Koster (//Field Two) and its work, thank you... but i want add code, when the date is not set in the database, it does not show anything ... Any tips??
Edgar, I cannot claim to understand how this works 100% but it does work.
Thanks for posting - this is a real help!
Hey guys,
JavaScript has a bunch of functions for controlling how dates are displayed. Below I used "toLocaleDateString()", which formats a date as a string based on your settings, including the language. You can read more about it here.
$w.onReady(function () { // Get the date from the date field of the current item const date = $w("#myDataset").getCurrentItem().date; // Define the date preferences const options = { weekday: "short", year: "numeric", month: "long", day: "numeric" }; // Display the date in the text element using the defined preferences $w("#text1").text = date.toLocaleDateString("en-US", options); });
What if I want the date to display in Spanish?
Can you email me? I’ve seperated my address
Robert
@
Ayrshire
Daily news
.co.uk
Hi Lorraine, Robert,
I made a page with standard objects on an existing table of mine. So the result is this:
The first field is the standard date/time field the second is the 'converted' datetime to text. The third is the code from Lorraine.
// For full API documentation, including code examples, visit http://wix.to/94BuAAs $w.onReady(function () { // FIELD TWO $w("#repeater1").onItemReady( ($w, itemData, index) => { const monthNames = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"]; console.log(itemData.trail_at); console.log(itemData.trail_at.getDate().toString()); console.log(monthNames[itemData.trail_at.getMonth()]); console.log(itemData.trail_at.getFullYear().toString()); console.log(itemData.trail_at.getHours().toString()); console.log(itemData.trail_at.getMinutes().toString()); const strDate = itemData.trail_at.getDate().toString(); const strMonth = monthNames[itemData.trail_at.getMonth()]; const strYear = itemData.trail_at.getFullYear().toString(); const strHour = ("0" + itemData.trail_at.getHours().toString()).slice(-2); const strMinute = ("0" + itemData.trail_at.getMinutes().toString()).slice(-2); $w("#text13").text = strDate + " " + strMonth + " " + strYear + " | " + strHour + ":" + strMinute; }); // FIELD THREE $w("#dynamicDataset").onReady(()=>{ let itemObj = $w("#dynamicDataset").getCurrentItem(); $w("#text15").text = itemObj.trail_at.toDateString(); }); });
All the code is above. In this code 'trail_at' can be any date/time field.
So first for Lorraine, you are using the dataset data. Your '#myDataset ' is my '#dynamicDataset'. I'm using the repeater data 'repeater1' which triggers the code when each item in it is ready (say displayed). That's the difference. I think you can you the dataset item too, but then you need to change more of the code and I don't see some called 'forEach' to make a loop. So I suggest to switch to the repeater object.
Then for Lorraine and Robert, sure I can help make adjustments like Robert asks, not a problem. Do check my profile though. Also you will need to pass a mail address, I don't put mine in posts, and the form lacks a pm function. Some security tip if you pass a mail address in a forum, don't do it 'attached' but use spaces or put it in an image. This way sniffers can't get it so easily.
Edgar,
If I pay you, will you go into my editor and implement this? :)
Thanks. I wish I knew enough to know the difference. I appreciate the help.
No, I assign the repeater data with the API for it's multilingual. It can also be your 'getCurrentItem'. I see you are doing it on a dataset ready and I'm doing it on item ready. That will be a major difference. I'll read about it tonight see if I see something
Here's the example- I wonder why its working for you but not for us? Was the date already on the repeater originally or you added a text block to the repeater?
Hey guys. What part is not correct then in a repeater? I have a repeater on my site, see print bellow, and format the date too, and hides the section if there is no date. I do it the same way, only not with named months and so on.
Yes Lorraine, you are right...using the above code works with Dynamic Pages and partially works with Repeaters.
With repeaters the above code formats the date, but it's the same date that shows in every item inside the repeater? Is there a solution or are we doing something wrong.
Here is the code for removing zeros for a text field linked to the date field of your dataset:
$w.onReady(function () {
$w("#myDataset").onReady(()=>{
let itemObj = $w("#myDataset").getCurrentItem();
$w("#text1").text = itemObj.valuenameofdatefield.toDateString();
});
});
Create a onReady event for your dataset, and then change the "#myDataset" to your dataset's name, the #text1 to your text's id name and the valuenameofdatefield to the value name of the date field you are connecting to. Here's a quick video too.
https://www.youtube.com/watch?v=6jM4J5LzMk0
However Wix Code team, if I try this with a repeater, it does indeed remove the zero's but it is only bringing up the date of the first repeater's date across all the other boxes. Should I be modifying the code in some way or is this a glitch? Would love to get an answer because I plan to use this so much!
Ah. There are two things. The first you see now, the second you would get later. The code must be in the onReady function. Place everything from line 11 to 29 between e.g. 8 and 9.
Also, change the column 'trail_at' with your column with the date in the table,
What does the console line show? Can you post the code where you put it, and a screenshot of the console when you preview it, and/or the console log of the live site? console lines will appear in e.g. chrome F12 debugger tab console.
Hey man, thanks so much! It's not working though - when i view live it's not showing anything?