I found this post about getting the current date in XAML. I gave it a try in a Mashup.
Here’s the code to get the current date and time in various formats in a Mashup. You can complement this with the Date picker in Mashup.
<Grid … xmlns:sys=”clr-namespace:System;assembly=mscorlib”>
<TextBlock Text="{Binding Source={x:Static sys:DateTime.Today}, StringFormat='Today is: {0:dddd, MMMM dd, yyyy, hh:mm:ss}'}" /> <TextBlock Text="{Binding Source={x:Static sys:DateTime.Today}, StringFormat='One of LSO formats: {0:MMddyy}'}" /> <TextBlock Text="{Binding Source={x:Static sys:DateTime.Today}, StringFormat='M3 API format: {0:yyyyddMM}'}" /> <TextBlock Text="{Binding Source={x:Static sys:DateTime.Today}, StringFormat='\{0:yyyy/MM/dd}'}" /> <TextBlock Text="{Binding Source={x:Static sys:DateTime.Today}, StringFormat='\{0:yyyyddMM}'}" />
And here is a screenshot of the result with the current date displayed in five different formats:
UPDATE 2012-03-26: To get the date in a TextBox add the binding property Mode=OneWay, for example:
<TextBox Text="{Binding Source={x:Static sys:DateTime.Today}, StringFormat='yyyy', Mode=OneWay}" />
This was a great help! Thanks to you, I figured out how to use a datepicker to select a value in one date format, then send this value to a MI transaction in the M3 API format 😀
LikeLike
Hello ,
I initialize my date at today : sys:DateTime.Now
Is it possible to display , the first day of the current month ?
Brs
LikeLike
i tried the same but didn’t work the API needs yyyymmdd but the date picker send 2019-01-01.
LikeLike
Hi Fredrik, I’m glad it helped you 🙂
LikeLike
Is it possible to bind a date where it is today MINUS 14 days? Why shouldn’t this line of code work?
LikeLike
Hi Eric. It might be possible, I don’t know. Otherwise, write a script for it and attach it to the Mashup. /Tibo
LikeLike
I have done a bunch of researching how to call a JScript from a Mashup and it feels like it will not work. I did in fact create a JScript with a date funtion however I can’t seem to use it from the resource in the Mashup; even though it is in the manifest file. I’ve seen Karin’s post where the subject was brought up and the response was that it doesn’t work. When you say “script” would that mean a C# script? I have existing JScript running in the Mashup but it doesn’t seem to work the other way around.
LikeLike
I guess the correct way would be to create a Converter with the Smart Office SDK.
LikeLike
I think this would be far easier to create a simple web service with some parameters. Thoughts?
LikeLike
Hello ,
I initialize my date at today : sys:DateTime.Now
Is it possible to display , the first day of the current month ?
Brs
LikeLike
Bonjour Christian, I don’t know how to do that in XAML alone. You will probably need to create a converter in C# with Smart Office SDK, or ask karinpb on the Smart Office blog.
LikeLike
Christian, maybe you could use function expressions in variable replacements: http://smartofficeblog.com/2014/08/06/function-expressions-in-variable-replacements/
LikeLike
Hi Christian, it is possible to initialize a datepicker to the first date of the month.
You must use a converter with formated date :
In grid resources :
and in your control like datepicker :
LikeLike
Hello,
In my mashup, I am using this binding for a textbox :
{Binding Source={x:Static sys:DateTime.Now}, StringFormat={}{0:MM/dd/yyyy HH:mm:ss}, Mode=OneWay}
which works perfectly fine (thanks to this post :))
But now I am trying to regenerate this field’s value when I click on a button (to get the new current time).
I tried adding an event on the button click using the ‘SetProperty’ on my Textbox’s ‘Text’ value but it seems the time isn’t re-calculated… (I’m guessing it has something to do with the ‘Static’ part)
Is there any way to force this?
Thanks,
Best regards
LikeLike
Bonjour Thomas. Did you try the conditions, converters, and property setters? There are examples in the Mashup Designer > Help > Common Controls. Probably the property setter would work. I think this is more of a WPF/XAML question than a Smart Office Mashup question, and I have not done this before so I do not have an answer right now. Maybe remove Mode=OneWay. Did you search on the Internet? Maybe ask Karin or ask on the PotatoIT forum. /Thibaud
LikeLike
are people still out there?
I was wondering if it was possible to do something like this, but instead find the current period, or at least year & month, to populate a text box in the column header in FCS001 for a mashup
LikeLike
Hello,
I am trying this “{Binding Source={x:Static sys:DateTime.Today}, StringFormat=’{0:ddMMyy}’}” webmashup. Unfortunately its not working. Do we have any other way to populate current date in webmashup?
Thanks in advance.
LikeLike