I'm trying to build a simple page for adding news documents to my site from my mobile. I would like to be able to pick a date (from an asp calendar control) for when the news document should be published. I've been fooling around with the ReleaseDate property on the Document class, but oddly enough it returns the date: 01-01-0001 even if I set the publish at date in Umbraco to 15-01-2011 for example.
Yep Releasedate is the property.. Think I was wrong in my first answer. I did an import myself which is basically doing the same as you are doing and data is stored as 2011-06-30 00:00 so the format is year-month-day
Ahh, you're right! The date is actually displayed as year-month-day in Umbraco! /facepalm.
Hmm, but shouldn't:
doc.ReleaseDate.ToString();
output: 01-19-2011 00:00 instead of 01-01-0001 00:00:00 then? Or does it output 01-01-0001 00:00:00 because the date time format is wrong?
I feel quite lost when it comes to formatting datetime in C# to be honest :( With the risk of sounding helpless: do you have an example/hint as how to format the date to correspond the date in Umbraco?
The releasedate .ToString outputs correct but Umbraco doesn't understand it. In CMSImport (which I took a look at) I just assign the database value which was stored as '2011-06-30 00:00:00.000'
If you want to add a formatten to the ToString method you shoudl take a look at http://idunno.org/archive/2004/07/14/122.aspx Best article on this subject. From the top of my head you should use doc.ReleaseDate.ToString("yyyy-MM-dd");.
Thanks again for your response :) It's greatly appreciated!
I just got the chance to take a look at this problem again now and I tried the doc.ReleaseDate.ToString("yyyy-MM-dd"); which returns "0001-01-01". I then found the document in the database and the date is correctly set to 2011-02-10 08:08:00 as I set in Umbraco.
the asp control I'm using is a DropDownList control.. So this code fires when the selection has changed. I think it's safe to say that I'm totally confused about this ;)
Then it outputs the correct ReleaseDate and ExpireDate.
My only question is... why? It can display all the other data such as bodyText and header etc, but can't display the releasedate and exp.date if it's not a new document?
C# Publish At
Hi all,
I'm trying to build a simple page for adding news documents to my site from my mobile. I would like to be able to pick a date (from an asp calendar control) for when the news document should be published. I've been fooling around with the ReleaseDate property on the Document class, but oddly enough it returns the date: 01-01-0001 even if I set the publish at date in Umbraco to 15-01-2011 for example.
Has anyone got any experience with this? :)
Any help or hint is greatly appreciated!
Thanks in advance,
Bo
Hi Bo,
Think you need to format your date to 01/15/2011. Umbraco is quite strict about that.
Cheers,
Richard
Hi Richard, thanks for your reply! :)
Good point about the datetime format there! However, i just tried the following code:
And it shows: "01-01-0001 00:00:00" in the TextBox aswell (?)
Isn't RelaseDate the same as "Publish At" in Umbraco, or?
Thanks again!
.. and it's the exact same with Expire Date / Unpublish at.. Have I missed something here? :/
Yep Releasedate is the property.. Think I was wrong in my first answer. I did an import myself which is basically doing the same as you are doing and data is stored as 2011-06-30 00:00 so the format is year-month-day
I've seen more issues with date.ToString().
Cheers,
Richard
Ahh, you're right! The date is actually displayed as year-month-day in Umbraco! /facepalm.
Hmm, but shouldn't:
output: 01-19-2011 00:00 instead of 01-01-0001 00:00:00 then? Or does it output 01-01-0001 00:00:00 because the date time format is wrong?
I feel quite lost when it comes to formatting datetime in C# to be honest :( With the risk of sounding helpless: do you have an example/hint as how to format the date to correspond the date in Umbraco?
Thanks again!
Bo
Hi Bo,
The releasedate .ToString outputs correct but Umbraco doesn't understand it. In CMSImport (which I took a look at) I just assign the database value which was stored as '2011-06-30 00:00:00.000'
If you want to add a formatten to the ToString method you shoudl take a look at http://idunno.org/archive/2004/07/14/122.aspx Best article on this subject. From the top of my head you should use doc.ReleaseDate.ToString("yyyy-MM-dd");.
Hope this helps you,
Richard
Hi Richard,
Thanks again for your response :) It's greatly appreciated!
I just got the chance to take a look at this problem again now and I tried the doc.ReleaseDate.ToString("yyyy-MM-dd"); which returns "0001-01-01". I then found the document in the database and the date is correctly set to 2011-02-10 08:08:00 as I set in Umbraco.
.. what's the deal?
This is my code in question:
the asp control I'm using is a DropDownList control.. So this code fires when the selection has changed. I think it's safe to say that I'm totally confused about this ;)
O.k I figured it out! However, the solution is quite weird to me.
In my Selection_Changed event I have to new up a new document in the foreach loop with the id of the current document like this:
Then it outputs the correct ReleaseDate and ExpireDate.
My only question is... why? It can display all the other data such as bodyText and header etc, but can't display the releasedate and exp.date if it's not a new document?
Can anyone clarify this?
is working on a reply...