Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Alex 30 posts 120 karma points
    Feb 26, 2015 @ 00:31
    Alex
    0

    formatasdate

    Hi everyone,

    I have used successfull @Umbraco.Field("mydatefield", formatAsDate: true) to format a date the way I would like it to display, however I am have difficulties for child page elements when it is @page.mydatefield. How could I format this properly?

     

  • Jan Skovgaard 11280 posts 23678 karma points MVP 10x admin c-trib
    Feb 26, 2015 @ 05:25
    Jan Skovgaard
    100

    Hi Alex

    You should be able to do something like this @page.mydatefield.Date.ToString("MMMM dd, yyyy")

    Does that work for you?

    /Jan

  • Thomas T 66 posts 227 karma points
    Feb 26, 2015 @ 08:18
    Thomas T
    0

    Hi Jan and Alex,

                           I used datepicker datatype in my site for events listing. It shows date with time in page. I need only date..How to do this?

             

  • Dennis Aaen 4499 posts 18254 karma points admin hq c-trib
    Feb 26, 2015 @ 08:22
    Dennis Aaen
    0

    Hi Thomas,

    I think is because you are using the data type called datepicker with time, there is also one just called datepicker, and then you should only get the date.

    Hope this helps,

    /Dennis

  • Thomas T 66 posts 227 karma points
    Feb 26, 2015 @ 08:37
    Thomas T
    0

    Hi Dennis,

                       I changed the datatype as datepicker. But it shows date with time as 3/20/2014 12:00:00 AM..... the time is binded by default in all event date...

  • Dennis Aaen 4499 posts 18254 karma points admin hq c-trib
    Feb 26, 2015 @ 08:43
    Dennis Aaen
    0

    Hi Thomas,

    Did you also publish the nodes after you have changed the datatype as datepicker? The XML cache needs to be updated after you have changes a page. So try to publish the event nodes again, or make a republish the entire site. How did you razor code look like for outputting the date?

    Hope this helps,

    /Dennis

  • Thomas T 66 posts 227 karma points
    Feb 26, 2015 @ 08:58
    Thomas T
    0

    Hi Dennis,

                     I republished entire site..But it didn't work.... events are listed out from media section....My partial view code is as below,

     

    @{    var mediaFolderId = (int)CurrentPage.NewsMediaFolder; }

    @if (mediaFolderId > 0)

    {

        var mediaFolder = Umbraco.TypedMedia(mediaFolderId);

       var newslist = mediaFolder.Children(x => x.DocumentTypeAlias == "News").ToList();

       foreach (var news in newslist)

          {

      <div class="col-md-6 pressmain1">

                <div class="col-md-6 pressimgdiv">

                   <img class="img-responsive" src="@(news.GetPropertyValue<string>("newsimage"))"> 

                </div>

                <div class="col-md-6 pressmain2">

                   <p class="presshead">@(news.GetPropertyValue<string>("newstitle"))</p>

                   <p class="calender">

     <i class="fa fa-calendar calendericon"></i> @(news.GetPropertyValue<string>("newsdate"))</p>

                   <p class="presscontent">

    @(news.GetPropertyValue<string>("newscontent"))

      </p>

                </div>

            </div>

    }

    }

  • Dennis Aaen 4499 posts 18254 karma points admin hq c-trib
    Feb 26, 2015 @ 09:07
    Dennis Aaen
    0

    Hi Thomas,

    Okay you are using strongly typed Razor syntax. For outputting the date try to use this snippet

    @(news.GetPropertyValue<DateTime>("newsdate").ToString("dd-MM-yy"))

    Hope this helps,

    /Dennis

  • Thomas T 66 posts 227 karma points
    Feb 26, 2015 @ 10:02
    Thomas T
    0

    Hi Dennis,

                                It works fine with that snippet. Thank you... In case, if it needs to show time only with hours, seconds and AM / PM along with date, how can I do it ?

               for eg.,       16-03-2015   04:30 AM

  • Jan Skovgaard 11280 posts 23678 karma points MVP 10x admin c-trib
    Feb 26, 2015 @ 10:12
    Jan Skovgaard
    0

    Hi Thomas

    Then you write time settings as the parameter like

    @(news.GetPropertyValue<DateTime>("newsdate").ToString("dd-MM-yy hh:mm tt"))
    

    Hope this helps.

    /Jan

  • Thomas T 66 posts 227 karma points
    Feb 26, 2015 @ 10:20
    Thomas T
    0

    Hi Jan,

                  It works fine now...thank you.

  • Thomas T 66 posts 227 karma points
    Feb 26, 2015 @ 11:01
    Thomas T
    0

    Hi Jan,

                  I have startdate and enddate for events...I need to display dates when both r given. ( 16-03-2015 to 18-03-2015)

    If startdate is only provided, then i need to display start date only. (16-03-2015).

    But it shows with default value for enddate ( 16-03-2015 to 01-01-0001 )...How to check enddate has default value ?

  • Dennis Aaen 4499 posts 18254 karma points admin hq c-trib
    Feb 26, 2015 @ 11:56
    Dennis Aaen
    1

    Hi Thomas,

    You can check if a field has a value by using the .HasValue, So I think this codesnippet should do it for you. Or at least gives you some idea on how you can do this.

    @if(news.HasValue("startdate") || news.HasValue("enddate")){ 
        <p class="calender"><i class="fa fa-calendar calendericon"></i>
        @if(news.HasValue("startdate")){
            @(news.GetPropertyValue<DateTime>("startdate").ToString("dd-MM-yy hh:mm tt"))
        }
        @if(news.HasValue("enddate")){
            @(news.GetPropertyValue<DateTime>("enddate").ToString("dd-MM-yy hh:mm tt"))
        }
       
     }

    Hope this helps,

    /Dennis

  • Thomas T 66 posts 227 karma points
    Feb 26, 2015 @ 14:07
    Thomas T
    0

    Hi Dennis,

                      Okay....it works now..thank you....

Please Sign in or register to post replies

Write your reply to:

Draft